如何将istream的指针移动n个字符? [英] How to move the pointer of istream by n characters?

查看:98
本文介绍了如何将istream的指针移动n个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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,我刚刚使用istream :: read读取了一个虚拟变量?

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

或者我使用的壳是n = istream :: tellg和istream :: seekg = n + 1000?

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

推荐答案

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

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.

这篇关于如何将istream的指针移动n个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆