首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

程序出错了大侠帮帮忙!该如何解决

2012-02-19 
程序出错了大侠帮帮忙!#include vector#include iostreamusing namespace stdint main(){ vectorstr

程序出错了大侠帮帮忙!
#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> (另外操作符'<<'中间没有空格)

热点排行