Printing the Size of Vector String Elements

I have created a program that takes user inputs and places the inputs of strings into a vector. My issue is I want to display the size of the strings that have been input into the vector. I under stand that using:
sizeof(vec[i])
in my for loop to display my input size only displays the size in bytes of the vector.
However when I use:
str.size(vec[i])
I get an error telling me that str was not declared in the scope when I have the "string" library included. Am I going about printing the sizes wrong or is there something I do not know yet. As I am still a beginner, please feel free to point out any other issues and guide me to a solution. Thanks! Source code below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#ifndef HEADER_H
#define HEADER_H
#include <iostream>
#include <vector>
#include <string>

using namespace std;

class Strings
{
    private:
        enum cat { single = 1, palindrome, withdigits, other };

    public:
        vector<string> vec;

        void setSingle(string x);


        void DisplayVector()
        {
            for(unsigned int i = 0; i < vec.size(); i++)
            {
                cout << str.size(vec[i]) << ", ";
            }
        }
};

#endif // HEADER_H 
1
2
// cout << str.size(vec[i]) << ", ";
cout << vec[i].size() << ", ";
Yes! It worked! Thank you so much. Oddly enough I used that same syntax but received an error. I must have tried to put something in the parentheses after size or just used size(vec[i]) which also gives me errors.
Topic archived. No new replies allowed.