std::rewind
Defined in header <cstdio> | | |
---|---|---|
void rewind( std::FILE* stream ); | | |
将文件位置指示符移动到给定文件流的开头。
这个函数相当于std::fseek(stream, 0,SEEK_SET);
,除非文件末尾和错误指示符被清除。
该函数从以前的调用中删除对ungetc
...
参数
stream | - | file stream to modify |
---|
返回值
%280%29
例
二次
#include <cstdio>
int main()
{
std::FILE *f;
char ch;
char str[20];
f = std::fopen("file.txt", "w");
for (ch = '0'; ch <= '9'; ch++) {
std::fputc(ch, f);
}
std::fclose(f);
std::FILE* f2 = std::fopen("file.txt", "r");
unsigned int size = std::fread(str, 1, 10, f2);
std::puts(str);
std::printf("\n%u\n",size);
std::rewind(f2);
unsigned int size2 = std::fread(str, 1, 10, f2);
std::puts(str);
std::printf("\n%u",size2);
std::fclose(f2);
}
二次
另见
fseek | moves the file position indicator to a specific location in a file (function) |
---|
C文件用于倒带
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com