i want to itterate through the vector and want to check if entered string is present in the string vector or not.. so please help me to know how can i do it
i have done just as we do to itterate through vector<string>:

vector<string>::iterator it;

cout << "myvector contains:";
for ( it = file_user.begin() ; it != file_user.end(); it++ );
cout << (*it)<< " " ;

cout << endl;

but its showing error as follows


1>.\assignment2.cpp(117) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::basic_string<_Elem,_Traits,_Ax>' (or there is no acceptable conversion)

please tell me what is it.

First, you have an excess semi-colon in the for-loop line, this will actually cause the loop to do nothing and try to dereference the end iterator (possibly a segmentation fault or access violation). The line should be:

for ( it = file_user.begin() ; it != file_user.end(); it++ ) //notice no ; at the end.

The error message you get is weird to me, it should work fine. Quick fix, just use this line instead:

cout << it->c_str() << " " ;

This will get the char* version of the string (which is the same type as "" literal strings, which already work in your example).

you should include <string>

you should include <string>

Probably your best choice.

This is one thing that I really don't like about how C++ works. The type std::string is a "built-in" class, but you need to #include the <string> header in order to do anything with it. You can't even create a vector, map, etc. without #include-ing the proper header? Why should be be able to with a string?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.