main172.cpp
#include
#include
#include
using namespace std;
void main172()
{
ofstream fout;
cout<<”Enter the filename.txt:”;
char filename[50];//用char
cin>>filename;
fout.open(filename);
while(fout.fail())
{
cout<<”wrong!”<<endl;
cout<<”Enter the filename.txt:”;
cin>>filename;
fout.open(filename);
}
cout<<"Enter the str:";
string str;
while(cin>>str)//&&!fout.fail())
//while(!fout.eof())不知道为什么,不能正确处理文件尾
{
//cin>>str;
//getline(cin,str);
fout<<str;
cout<<”Enter the str:”;
}
fout.close();
}
—————————————————————————————————————————————————— //写的错误或者不好的地方请多多指导,可以在下面留言或者给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。 转载请注明出处:https://www.royalchen.com/ author:royalchen Email:royalchen@royalchen.com ———————————————————————————————————————————————————
- 本文作者: royalchen
- 本文链接: http://www.royalchen.com/2016/02/24/cprimerplus第六版课后编程题答案172/
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!