std::clearerr

Header: <cstdio>

Resets the error flags and the EOF indicator for the given file stream.

# Declarations

void clearerr( std::FILE* stream );

# Parameters

# Return value

(none)

# Example

#include <cassert>
#include <cstdio>
 
int main()
{
    std::FILE* tmpf = std::tmpfile();
    std::fputs("cppreference.com\n", tmpf);
    std::rewind(tmpf);
 
    for (int ch; (ch = std::fgetc(tmpf)) != EOF; std::putchar(ch)) { }
 
    assert(std::feof(tmpf)); // the loop is expected to terminate by EOF
    std::puts("End of file reached");
 
    std::clearerr(tmpf); // clear EOF
 
    std::puts(std::feof(tmpf) ? "EOF indicator set"
                              : "EOF indicator cleared");
}

# See also