程序出错了大侠帮帮忙!
#include <vector>
#include <iostream>
using namespace std;
int main()
{
vector<string>svec;
svec.reserve(1024);
cout<<svec.size()<<" "<<svec.capacity();
string text_word;
while (cin>>text_word)
svec.push_back(text_word);
cout<<svec.size()<<" "<<svec.capacity();
svec.resize(svec.size()+svec.size()/2);
cout<<svec.size()<<" "<<svec.capacity();
return 0;
}
错误:
--------------------Configuration: fkf6201 - Win32 Debug--------------------
Compiling...
fkf6201.cpp
d:\vc程序\fkf6201.cpp(12) : 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)
d:\vc程序\fkf6201.cpp(12) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.
fkf6201.obj - 2 error(s), 0 warning(s)
[解决办法]
#include <vector>
#include <iostream>
#include <string>
using namespace std;
int main()
{
vector <string> svec;
svec.reserve(1024);
cout <<svec.size() << " " <<svec.capacity();
string text_word;
while (cin >> text_word)
svec.push_back(text_word);
cout << svec.size() << " " << svec.capacity();
svec.resize(svec.size()+svec.size()/2);
cout <<svec.size() << " " <<svec.capacity();
return 0;
}
// 缺少头文件 <string> (另外操作符'<<'中间没有空格)