Returning to beginning of file after getline

前端 未结 3 528
你的背包
你的背包 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条回答
  •  -上瘾入骨i
    2020-12-02 17:38

    This is because the eof flag has been set on the stream - due to you reaching the end of the file. so you have to clear this as an additional step.

    Eg

    ifile.clear();
    ifile.seekg (0, ios::beg);
    

提交回复
热议问题