nemaroller
Dec 10th, 2001, 07:44 PM
I simply want to extract some values from a string vector, but the following code gives me errors
#include<iostream.h>
#include<vector>
#include<string>
using namespace std;
void main(){
vector<string> r;
r.push_back("Hi");
r.push_back("There");
cout << r[0] << endl;
cout << r[1] << endl;
}
errors:
C:\Windows\vectorsample.cpp(10) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion
)
C:\Windows\vectorsample.cpp(11) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion
)
So I'm guessing that the << operand wont automatically extract a string vector(although it works with int,char,etc)....
How do I do this? Do I need to overload the << operator, and if so, could someone explain to me how to do this, in code, or otherwise.
Thank you...
#include<iostream.h>
#include<vector>
#include<string>
using namespace std;
void main(){
vector<string> r;
r.push_back("Hi");
r.push_back("There");
cout << r[0] << endl;
cout << r[1] << endl;
}
errors:
C:\Windows\vectorsample.cpp(10) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion
)
C:\Windows\vectorsample.cpp(11) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion
)
So I'm guessing that the << operand wont automatically extract a string vector(although it works with int,char,etc)....
How do I do this? Do I need to overload the << operator, and if so, could someone explain to me how to do this, in code, or otherwise.
Thank you...