How to move the pointer of istream by n characters?

淺唱寂寞╮ 提交于 2020-05-11 07:19:07

问题


I would like to skip a few characters in a binary file between two istream getlines. What is the best way to do it?

Shell I just read into a dummy variable with istream::read?

Or shell I use n = istream::tellg and istream::seekg = n + 1000?


回答1:


You can simply move a stream position relative to the current position by using the std::ios::cur position argument:

std::ifstream f("myfile.txt");   // current position 0
f.seekg(200, std::ios::cur);     // relative seek

Negative values are also permitted. See e.g. here.



来源:https://stackoverflow.com/questions/6403854/how-to-move-the-pointer-of-istream-by-n-characters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!