std::clearerr(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ¦‹ std::clearerr(3) β€” C++ Standard Libary πŸ¦‹

okay so bestie, welcome to the std::clearerr(3) page β€” C++ Standard Library corner of the group chat, stream-cleanup edition πŸ’…

✨ NAME ✨

std::clearerr β€” and yes, the name is literally std::clearerr, no cap. That's the whole name section, periodt. πŸ’–


🌸 Synopsis 🌸

Defined in header <cstdio> ✨

void clearerr( std::FILE* stream );

What it does: it resets the error flags and the EOF indicator for the given file stream. Lowkey the cleanup bestie for your stream's emotional baggage πŸ’…

πŸŽ€ Parameters πŸŽ€

  • stream β€” the file to reset the error flags for. That's the whole parameter list, bestie. 🫢

πŸ’– Return value πŸ’–

(none) β€” literally nothing comes back. No return value, no drama. 😭

πŸ¦‹ Example πŸ¦‹

Okay so here's the exact code from the page, run-it-yourself energy:

       // Run this code

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

πŸ“ Output: πŸ“

        cppreference.com
        End of file reached
        EOF indicator cleared

🌈 See also 🌈

  • feof β€” checks for the end-of-file. It's a function. πŸ‘‘
  • perror β€” displays a character string corresponding of the current error to stderr. It's a function. 🫢
  • ferror β€” checks for a file error. It's a function. πŸ’œ
  • C documentation for clearerr β€” go read the C docs for clearerr, bestie. πŸ¦‹

shoutout to http://cppreference.com, source/version date 2024.06.10, and that's the std::clearerr(3) page β€” periodt. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from