這是《C++ primer》第四版上的一個例子,向vector添加元素,使用push_back函數,我按照書上給出的樣例程序,在VC6.0裏編了一下,如下:
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
string word;
vector<string> text;
while(cin>>word){
text.push_back(word);
}
cout<<text<<endl;
return 0;
}
編譯時出現一個錯誤,如下:
error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::vector<class
std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<cla
ss std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >' (or there is no acceptable conversion)
大概的意思是說cout<<text<<endl這一行有錯誤。請問是爲什麼呢?