std::rewind
來自 cppreference.com
定義於標頭檔案 <cstdio> |
||
void rewind( std::FILE* stream ); |
||
將檔案位置指示器移動到給定檔案流的開頭。
該函式等同於 std::fseek(stream, 0, SEEK_SET);,但會清除檔案結束和錯誤指示器。
該函式會取消之前對 ungetc 的任何呼叫效果。
目錄 |
[編輯] 引數
stream | - | 要修改的檔案流 |
[編輯] 返回值
(無)
[編輯] 示例
執行此程式碼
#include <array> #include <cstdio> int main() { std::FILE* f = std::fopen("file.txt", "w"); for (char ch = '0'; ch <= '9'; ch++) std::fputc(ch, f); std::fclose(f); std::array<char, 20> str; std::FILE* f2 = std::fopen("file.txt", "r"); const unsigned size1 = std::fread(str.data(), 1, str.size(), f2); std::puts(str.data()); std::printf("size1 = %u\n", size1); std::rewind(f2); const unsigned size2 = std::fread(str.data(), 1, str.size(), f2); std::puts(str.data()); std::printf("size2 = %u", size2); std::fclose(f2); }
輸出
0123456789 size1 = 10 0123456789 size2 = 10
[編輯] 參閱
將檔案位置指示器移動到檔案中特定位置 (function) | |
C documentation for rewind
|