#include<fstream>
#include <iostream>
#include <string>
using namespace std;
int main()
{
char filename[2][30], ch;
int i = 0;
ifstream file1;
ofstream file2;
cout << "请输入源文件名" << endl;
cin >> filename[0];
cout << "请输入目标文件名" << endl;
cin >> filename[1];
file1.open(filename[0], ios::in);
if (file1.fail())
{
cout << "文件打开失败!" << endl;
return 1;
}
file2.open(filename[1], ios::out);
if (!file2)
{
cout << "文件打开失败!" << endl;
return 1;
}
string line;
while (!file1.eof())
{
getline(file1, line, '\n');
file2 <<++i<<"." << line << endl;
}
file1.close();
file2.close();
return 0;
}
打开指定的一个文本文件,在每一行前面加上行号。
最新推荐文章于 2024-05-18 23:57:26 发布