カンテラの光の下で

dNaga392's memorandom

【C++】ifstreamで一行戻す

ifstrean には「一行戻すため」の関数は存在しない。しかし、tellg()seekg() を用いることで実現できる。

std::ifstream myReadFile("route.txt");
....
auto oldpos = myReadFile.tellg();  // stores the position
getline(myReadFile, line);
myReadFile.seekg(oldpos);   // get back to the position

Go back one line on a text file C++ - Stack Overflow

参考資料