#include#include #include using namespace std; int main() { int counter = 0; string str; ifstream ifs("ww.txt"); ofstream ofs("aa.txt"); while (!ifs.eof()) { getline(ifs, str); if(!ifs.eof())//标记 ofs << ++counter << ". " << str << endl; } ; ifs.close(); ofs.close(); }
标记位置不能把文件尾判断换成字符串判空,或者换成str[0]!=0。因为文件中间可能有空行,或0开头的行。
如果去掉这个判断,会多出来一行,我也不知道为啥,按说不用判空呀,求解释一波。



