/*copyright(c)2016.烟台大学计算机学院
* All rights reserved,
* 文件名称:text.Cpp
* 作者:舒文超
* 完成日期:2016年6月4日
* 版本号:vc++6.0
* 问题描述:说出程序的功能,并上机验证(请自建a.txt)
*/
#include <iostream>
#include <fstream>
#include<cstring>
using namespace std;
int main()
{
ifstream readFile;
ofstream writeFile;
char ch[100]={"Hello world!!!"};
cout<<ch<<endl;
readFile.open("a.txt", ios::in);
writeFile.open("b.txt", ios::out);
while (!readFile.eof())
{
readFile.getline(ch,100,'\n');
writeFile.write(ch,strlen(ch));
writeFile.write("\n",1);
}
cout<<ch<<endl;
readFile.close();
writeFile.close();
cout << "Finish!" << endl;
return 0;
}
运行结果:
作用:将字符串中的内容用a记事本中的内容替换,然后再将b记事本中的内容用字符串中的内容替换。
解释:为了更加明显地看出这段代码地作用,我在以上代码中做了一点手脚(加了两行代码:第18与第27行)。