/**编程题1
从键盘输入一个文本文件名,将文件中每行前面加上行号和一个冒号,行号从1开始,保存在另一文件中。例如:
1: This is a test.
2: I am a student.
3: I love China.
*/
#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>
using namespace std;
int main(){
string file1,file2;
int l=1;
char ch;
cout<<"请输入要打开的文件名:"<<endl;
getline(cin,file1);
fstream wfile1(file1.c_str(),ios_base::in);
cout<<"请输入要写入的文件名:"<<endl;
getline(cin,file2);
fstream wfile2(file2.c_str(),ios_base::out);
wfile2<<l<<":";
l++;
while(wfile1.get(ch)){
wfile2<<ch;
if(ch=='\n'){
wfile2<<l<<":";
l++;
}
}
wfile2<<"\0";
wfile1.close();
wfile2.close();
return 0;
}