首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++中seekg()跟seekp()是否相同

2012-09-25 
C++中seekg()和seekp()是否相同?起初我以为这两个是不相同的,但是经过测试发现这两个用的好像是同一个文件

C++中seekg()和seekp()是否相同?
起初我以为这两个是不相同的,但是经过测试发现这两个用的好像是同一个文件指针,请问如果我写的时候用seekg()会出错吗?为什么要用两个函数啊?

[解决办法]

探讨

文件偏移量是一样的,但读写模式不一样,必须经过一次转换。

[解决办法]
seekg中g是get的缩写,用于输入流
seekp中是put的缩写,用于输出流

如果是输入输出流(同时支持输入和输出),可能都可以。
[解决办法]
seekg :
Input file streams keep an internal pointer to the position in the file where data is to be read next. You set this pointer with the seekg function, as shown here:
------------------
The seekp Functions
An output file stream keeps an internal pointer that points to the position where data is to be written next. The seekp member function sets this pointer and thus provides random-access disk file output. The tellp member function returns the file position. For examples that use the input stream equivalants to seekp and tellp, see The seekg and tellg Functions.

热点排行
Bad Request.