std::ferror(3)
π¦ std::ferror(3) π¦ β C++ Standard Libary
okay so bestie, we are in the C++ Standard Libary and this is the page for std::ferror(3). The header is giving βtiny but iconic,β and the manual name is literally C++ Standard Libary. Yes, that spelling is what the header says, not me, ily. π
π NAME π
std::ferror - std::ferror
literally the name, no cap. The page is std::ferror(3), and the NAME section is just the same thing twice like a mirror selfie. πͺβ¨
π Synopsis π
Defined in header <cstdio>
int ferror( std::FILE* stream );
This bad boy checks the given stream for errors. You hand it a stream, it tells you if that stream has error energy. π«Ά
π Parameters π
streamβ the file stream to check. Thatβs the thing youβre side-eyeing for errors, bestie.
πΈ Return value πΈ
Nonzero value if the file stream has errors occurred, 0 otherwise.
So: nonzero means errors happened on that file stream; 0 means no errors found. Simple, clean, iconic. β¨
π§ Example π§
Run this code, fr fr:
// Run this code
#include <clocale>
#include <cstdio>
#include <cstdlib>
#include <cwchar>
int main()
{
const char *fname = std::tmpnam(nullptr);
std::FILE* f = std::fopen(fname, "wb");
std::fputs("\xff\xff\n", f); // not a valid UTF-8 character
sequence
std::fclose(f);
std::setlocale(LC_ALL, "en_US.utf8");
f = std::fopen(fname, "rb");
std::wint_t ch;
while ((ch=std::fgetwc(f)) != WEOF) // attempt to read as UTF-8
std::printf("%#x ", ch);
if (std::feof(f))
puts("EOF indicator set");
if (std::ferror(f))
puts("Error indicator set");
}
the stray sequence line is in the original snippet too, bestie β donβt come for me ππ
π Output π
Error indicator set
π See also π
clearerrβ clears errors. Itβs a function.feofβ checks for the end-of-file. Itβs a function.failβ checks if an error has occurred. Itβs a public member function ofstd::basic_ios<CharT,Traits>.- C documentation for
ferrorβ yes, the C version of this whole situation.
okay thatβs the whole manual page, mwah π β source: cppreference.com, version/date: 2024.06.10, page: std::ferror(3). π«Άπ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms