# std::rewind

From cppreference.com
< cpp‎ | io‎ | c

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 to std::fseek(stream, 0, SEEK_SET);, except that end-of-file and error indicators are cleared.

The function drops any effects from previous calls to ungetc.

### Parameters

stream | - | file stream to modify

### Return value

(none)

### Example

Run this code

    #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);
    }

### See also

fseek | moves the file position indicator to a specific location in a file (function)

Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/c/rewind&oldid=70168"