这次仿佛有点累赘,等以后学习了更好方法会修改
#include <iostream>
using namespace std;
#include "fstream"
#include <cstdio> //remove 删除中间过度文件
void doit(char *oldname, char *newname="new.cpp")
{
//修改
ifstream ifile(oldname);
ofstream ofile(newname);
char c[1000];
int hang = 0;
while (!ifile.eof())
{
ifile.getline(c, 999);
hang++;
cout << c << endl;
ofile << hang << " " << c << endl;
}
ifile.close();
ofile.close();
//返回
ifstream ifile(newname);
ofstream ofile(oldname);
while (!ifile.eof())
{
ifile.getline(c, 999);
ofile << c << endl;
}
ifile.close();
ofile.close();
remove(newname);
}
void main()
{
doit("G://666.cpp");
cout<<"hello"<<endl;
system("pause");
return;
}