如何将istream的指针移动n个字符

How to move the pointer of istream by n characters?

本文关键字:移动 字符 指针 istream      更新时间:2023-10-16

我想跳过二进制文件中两个istream getline之间的几个字符。最好的方法是什么?

Shell我刚刚用istream::read?

或者shell我使用n=istream::tellg和istream::seekg=n+1000?

您可以简单地使用std::ios::cur位置参数相对于当前位置移动流位置:

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

负值也是允许的。例如,请参见此处。