我的程序读取* .txt文件,并从文件向后打印一行。
我想先获取行号。
循环后,我得到了我的电话号码,但是“for循环”之后的所有内容都无法打印/工作。我的代码有什么问题?

    if (testFile.good()) {

        int countLines = 0;
        string temp;

        for (int i = 0; getline(testFile, temp); i++)
                    countLines++;

        cout << countLines;

        aline.readLine(testFile);
}

最佳答案

重置流标志,以便您可以在aline.readLine(testFile);循环后再次在for中“执行操作”

testFile.clear();
testFile.seekg(0, testFile.beg);

关于c++ - C++主文件无法显示所有内容,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19140936/

10-09 19:55