您的位置:首页 > 其它

fseek

2015-12-11 11:15 183 查看
详情请看 http://www.cplusplus.com/reference/cstdio/fseek/
(1) fseek()

定义: int fseek ( FILE * stream, long int offset, int origin );


功能:重新设置stream的位置到offset处基于文件头/文件尾/当前位置

参数:stream: 只想一个文件对象的指针.

          offset:  二进制文件: Number of bytes to offset from origin.     文本文件: Either zero, or a value returned byftell.

          origin:  偏移基于的位置.

                     It is specified by one of the following constants defined in<cstdio> exclusively to be used as arguments for this function:

 ConstantReference position
SEEK_SET文件头
SEEK_CUR当前位置
SEEK_END文件
*
Library implementations are allowed to not meaningfully support SEEK_END (therefore, code using it has no real standard portability).

返回值: 成功返回0 失败返回非0
/* fseek example */
#include <stdio.h>

int main ()
{
FILE * pFile;
pFile = fopen ( "example.txt" , "wb" );
fputs ( "This is an apple." , pFile );
fseek ( pFile , 9 , SEEK_SET );
fputs ( " sam" , pFile );
fclose ( pFile );
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: