Click here to Skip to main content
16,015,218 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I am new to STL and trying to learn about vectors.

My code snippet looks like the following:
XML
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
int main() {
    vector< string > svec( 10, string( "Hi" ));
    for(vector<string>::iterator myIt= svec.begin();myIt != svec.end();myIt++) {
        cout << *myIt;
    }
    cout << endl;
}


But when I compile this I get the compiler error at statement:
cout << *myIt;


The error message is :
VB
Error   1   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) 8


How can I solve this,
Thanks in advance
Posted

1 solution

Try adding
#include <string>
 
Share this answer
 
v2
Comments
hakz.code 2-Jun-11 3:38am    
Hi,
that solved the error,but if string is not declared it should have given the error at the vector definition,right?!
thanks
Timberbird 2-Jun-11 3:53am    
You see, it may actually happen that string type is declared in headers you've already included, while operator << is not :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900