一定要写这么复杂么
试试
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char const *argv[])
{
ifstream fd;
fd.open("output.txt", ios::in);
char buf[1024];
int line = 0;
while (fd.getline(buf, sizeof(buf)))
{
cout << line << " : " << buf << endl;
line++;
}
}