【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