首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么我的程序中的第二个while循环在它之前有一个while循环时不能工作?

为什么我的程序中的第二个while循环在它之前有一个while循环时不能工作?
EN

Stack Overflow用户
提问于 2019-06-27 07:37:07
回答 1查看 42关注 0票数 0

这两个while循环单独工作。但是,如果上面有while循环,代码中的第二个while循环将无法工作。我需要这两个while循环一起工作。

代码语言:javascript
复制
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main(){
    string line, line1, line2;
    int count = 0;
    int track = 0;
    int stop;
    ifstream file ("ai.txt");
    while (getline(file, line2)){
        count++;
    }
    file.seekg (0L, ios :: beg);
    stop = count - 10;
    while (getline(file, line)){
        track++;
        if (track >= stop){
            for (int num = 1; num <=10; num++){
                getline(file,line1);
                cout << line1 << endl;   
            }
        }
    }

}

代码应该输出任何文本文件的最后十行。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56782183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档