小弟实在不知道哪里出问题了,望高手指点,先谢谢!
#include <iostream>
#include <cstring>
#include <vector>
#include <fstream>
using namespace std;
int main()
{
string filename;
cout<<"please enter name of file to open:";
cin>>filename; /*这里编译出错*/
if(filename.empty())
{
cout<<"filename is empty().bailing out.bye!\n";
return -1;
}
ifstream infile(filename.c_str());
if(!infile)
{
cout<<"unable to open.bailing out.bye!\n";
return -2;
}
string inbuf;
vector<string>text;
while(infile>>inbuf) /*这里编译出错*/
{
for(int ix=0;ix<inbuf.size();++ix)
if((char ch=inbuf[ix])=='.')
{
ch='_';
inbuf[ix]=ch;
}
text.push_back(inbuf);
}
if(text.empty())
return 0;
vector<string>::iterator iter=text.begin(),
iend=text.end();
while(iter!=iend)
{
cout<<*iter<<endl;
++iter;
}
return 0;
}
编译显示:D:\prob\prob.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)