I added a line to this program to read the length of the the string , then display the test. strlen() is not cooperating! Am I using the wrong function? the compiler says the arg should be char*. I'm confused!

#include <iostream>
#include <string>
#include <vector>
using namespace std;

vector <string> strv;

int main()
        string input;

                getline (cin,input);
        while(input !="x");
        cout << "exited first loop" << endl;

        vector <string>::iterator itr = strv.begin(); //put itr init here instead
        while (itr != strv.end())

        cout<< << "length= "<< strlen(*itr) << " "<< *itr++  << endl;

return 0;

*itr returns a string, not a char*. Use the .length() for the string instead.

Yes, that's what I needed. Thanks
I also had to fix the line so that the results printed where they belonged and stuck an equivalent method of member addressing on the end for kicks.

cout<<  "length= "<< ((*itr).length())<< " "<< *itr <<" " << itr -> length() <<endl;
This article has been dead for over six months. Start a new discussion instead.