是“寻求" & "seekg"可互换的? [英] are "seekp" & "seekg" interchangeable?

查看:94
本文介绍了是“寻求" & "seekg"可互换的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我刚刚注意到,通过在Microsoft Visual Studio中通过"seekp"更改位置,我隐式地还可以在处理文件时更改读取位置.

Well I just noticed that by changing the position -in microsoft visual studio- through "seekp" I implicitelly also change the read-position, when handling files.

但是我想知道这是否是便携式"行为?我可以期待阅读和阅读的位置吗?写作总是一样吗?因此:tellp& tellg总是返回相同的值吗?

I am wondering however if this is "portable" behaviour? Can I expect the position of reading & writing to be always the same? And consequently: will tellp & tellg always return the same value?

推荐答案

对于文件位置,它们是相同的.换句话说,仅维护了一个指针.

For file positions they are the same. In other words there is only one pointer maintained.

来自27.9.1.1p3:

输入序列和输入序列都保持联合文件位置 输出序列.

A joint file position is maintained for both the input sequence and the output sequence.

因此,seekgseekp对于文件流是可互换的.但是,对于其他类型的流,情况并非如此,因为它们可能为放置和获取位置持有单独的指针.

So, seekg and seekp are interchangeable for file streams. However, this is not true for other types of streams, as they may hold separate pointers for the put and get positions.

这篇关于是“寻求" & "seekg"可互换的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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