首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

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

二次

代码语言:javascript
复制
#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文件用于倒带

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com