请各位路过大神帮忙指点,为何下述程序无法正确实现将src.txt的内容每行加行号后输出到dst.txt?本人在命令行窗口输入test.exe src.txt dst.txt后,打开相应目录下的dst.txt发现仍旧为空:
#include
#include
#include
int main(int argc, char * argv[])
{
strstream textfile;
{
ifstream in(argv[1]);
textfile << in.rdbuf();
}
ofstream out(argv[2]);
const int bsz = 100;
char buf[bsz];
int line = 0;
while (textfile.getline(buf, bsz))
{
out.setf(ios::right, ios::adjustfield);
out.width(1);
out << ++line << ". " << buf << endl;
}
return 0;
}