Returning to beginning of file after getline

前端 未结 3 533
你的背包
你的背包 2020-12-02 17:14

So i\'ve read all the lines from a file thusly

while (getline(ifile,line))
    {
        // logic
    }

Where ifile is an ifstream and line

3条回答
  •  感动是毒
    2020-12-02 17:28

    Since you have reached (and attempted to read past) the end of the file, the eof and fail flags will be set. You need to clear them using ifile.clearthen try seeking:

    ifile.clear();
    ifile.seekg(0);
    

提交回复
热议问题