第八章课后练习题(P328_5_2)
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
using namespace std;
int main()
{
string file1,file2;
int l = 1;
char ch;
cout<<"请输入打开的文件名:"<<endl;
getline(cin,file1);
fstream tfile1(file1.c_str(),ios_base::in);
cout<<endl<<"请输入要写入的文件名:"<<endl;
getline(cin,file2);
fstream tfile2(file2.c_str(),ios_base::out);
tfile2<<l<<".";
l++;
while(tfile1.get(ch))
{
tfile2<<ch;
if(ch == '\n')
{
tfile2<<l<<".";
l++;
}
}
tfile2<<"\0";
tfile1.close();
tfile2.close();
cout<<"请结束程序后,打开文件查看结果。"<<endl<<endl;
system("pause");
return 0;
}

浙公网安备 33010602011771号