运行环境vc6!
先来看这段代码:
string fileName;
cout<<"Enter the fileName: ";
cin>>fileName;
string name;
ofstream fcout(fileName.c_str(),ios::out|ios::app);
while(getline(cin,name)&&name.size()>0)
{
cout<<name<<endl;
fcout<<name;
}
当你输入:xxxxx 时,函数并没有但因输出,这就要注意,getline函数读取了cin>>fileName最后的回车导致循环不被执行;
注意:这段代码在gcc下是正确运行的