| I/O manipulators | ||||
| Print functions(C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++20) | ||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
| Synchronized Output | ||||
(C++20) | ||||
| Types | ||||
| Error category interface | ||||
(C++11) | ||||
(C++11) |
| Types and objects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in header <cstdio> | ||
void rewind(std::FILE* stream); | ||
Moves the file position indicator to the beginning of the given file stream.
The function is equivalent tostd::fseek(stream,0,SEEK_SET);, except that end-of-file and error indicators are cleared.
The function drops any effects from previous calls toungetc.
Contents |
| stream | - | file stream to modify |
(none)
#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"); constunsigned size1=std::fread(str.data(),1, str.size(), f2);std::puts(str.data());std::printf("size1 = %u\n", size1); std::rewind(f2); constunsigned size2=std::fread(str.data(),1, str.size(), f2);std::puts(str.data());std::printf("size2 = %u", size2); std::fclose(f2);}
Output:
0123456789size1 = 100123456789size2 = 10
| moves the file position indicator to a specific location in a file (function)[edit] | |
C documentation forrewind | |