标签:c++ 文件 textfile close turn pre lin name 行号
#include <fstream>
#include <strstream>
using namespace std;
int main(int argc,char*argv[])
{
strstream textfile;
ifstream in(argv[1]);
textfile << in.rdbuf();
in.close();
ofstream out(argv[2]);
const int bsz = 100; //每次每行最多读取的字符数
char buf[bsz];
int line = 0;
while(textfile.getline(buf,bsz/*,‘\n‘*/)) //默认的终止符是回车
{
out.setf(ios::right,ios::adjustfield);
out.width(1); //不写也可
out << ++ line << ". " <<buf<<endl;
}
out.close();
return 0;
}
标签:c++ 文件 textfile close turn pre lin name 行号
原文地址:https://www.cnblogs.com/Jesse-Cavendish/p/14528337.html