C++官网参考链接:https://cplusplus.com/reference/cstdio/fsetpos/
函数
<cstdio>
fsetpos
int fsetpos ( FILE * stream, const fpos_t * pos );
设置流的位置指示符
将stream中的当前位置恢复为pos。
与stream相关联的内部文件位置指示符被设置为pos表示的位置,pos是指向fpos_t对象的指针,该对象的值应该在之前通过调用fgetpos获得。
成功调用此函数后,stream的文件尾内部指示符将被清除,并且在此流上先前调用ungetc所产生的所有效果将被删除。
在打开更新的流上(读+写),调用fsetpos允许在读和写之间切换。
一个类似的函数,fseek,可以用来设置以二进制模式打开的流的任意位置。
参数
stream
指向标识流的FILE对象的指针。
pos
指向fpos_t对象的指针,该对象包含先前使用fgetpos获得的位置。
返回值
如果成功,函数返回0。
如果失败,将返回一个非0值,并将errno设置为特定于系统的正值。
用例
/* fsetpos example */
#include <stdio.h>
int main ()
{
FILE * pFile;
fpos_t position;
pFile = fopen ("myfile.txt","w");
fgetpos (pFile, &position);
fputs ("That is a sample",pFile);
fsetpos (pFile, &position);
fputs ("This",pFile);
fclose (pFile);
return 0;
}
在此代码成功执行后,一个名为myfile.txt的文件将包含:

另请参考
fgetpos Get current position in stream (function)
fseek Reposition stream position indicator (function)
rewind Set position of stream to the beginning (function)