main173.cpp
#include
#include
#include
using namespace std;
void main173()
{
ofstream fout;
ifstream fin;
char filename[50];
cout<<”Enter the file source:”;//请输入当前目录下的文件,不可输入路径名,否则会出错
cin>>filename;
fin.open(filename);
while(!fin.is_open())//打开失败
{
cout<<”\nWrong filename ,can’t open it!”;
cout<<”Enter the file source:”;
cin>>filename;
fin.open(filename);
}
char copy[50]={“Copy”};
strcat(copy,filename);//要写入的文件,因为我是在前面+Copy的
fout.open(copy);
while(!fout.is_open())//打开失败
{
cout<<”\nWrong Copyfilename ,can’t open it!”;
fout.open(copy);
}
string temp;
while(!fin.fail())
{
getline(fin,temp);
fout<<temp;
fout<<endl;
}
if(fin.eof())
cout<<”Copy complete!”<<endl;
else
cout<<”copy failed!”<<endl;
fin.close();
fout.close();
cin.get();
}
—————————————————————————————————————————————————— //写的错误或者不好的地方请多多指导,可以在下面留言或者给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。 转载请注明出处:https://www.royalchen.com/ author:royalchen Email:royalchen@royalchen.com ———————————————————————————————————————————————————
- 本文作者: royalchen
- 本文链接: http://www.royalchen.com/2016/02/24/cprimerplus第六版课后编程题答案173/
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!