std::basic_ios::bad(3)
π
std::basic_ios::bad π
okay so welcome to the C++ Standard Libary corner of the group chat, bestie β this is std::basic_ios::bad(3), and weβre gonna get you fluent in it, no cap. πβ¨
πΈ NAME πΈ
std::basic_ios::bad β std::basic_ios::bad
β¨ Synopsis β¨
bool bad() const;
This absolute icon returns true if a non-recoverable error has occurred on the associated stream. Specifically, it returns true if badbit is set in rdstate(). π
See ios_base::iostate for the list of conditions that set badbit. iykyk π
π Parameters π
Parameters: (none) β literally zero arguments, she takes none, periodt. π«Ά
π Return value π
true if a non-recoverable error has occurred, false otherwise. Thatβs the whole vibe check, bestie. π
π§ͺ Example π§ͺ
okay so run this code, fr fr:
// Run this code
#include <cstdlib>
#include <fstream>
#include <iostream>
int main()
{
std::ifstream file("test.txt");
if (!file) // operator! is used here
{
std::cout << "File opening failed\n";
return EXIT_FAILURE;
}
// typical C++ I/O loop uses the return value of the I/O function
// as the loop controlling condition, operator bool() is used here
for (int n; file >> n;)
std::cout << n << ' ';
std::cout << '\n';
if (file.bad())
std::cout << "I/O error while reading\n";
else if (file.eof())
std::cout << "End of file reached successfully\n";
else if (file.fail())
std::cout << "Non-integer data encountered\n";
}
π See also π
The following table shows the value of basic_ios accessors (good(), fail(), etc.) for all possible combinations of ios_base::iostate flags:
eofbit=false,failbit=false,badbit=falseβgood()=true,fail()=false,bad()=false,eof()=false,operator bool=true,operator!=falseeofbit=false,failbit=false,badbit=trueβgood()=false,fail()=true,bad()=true,eof()=false,operator bool=false,operator!=trueeofbit=false,failbit=true,badbit=falseβgood()=false,fail()=true,bad()=false,eof()=false,operator bool=false,operator!=trueeofbit=false,failbit=true,badbit=trueβgood()=false,fail()=true,bad()=true,eof()=false,operator bool=false,operator!=trueeofbit=true,failbit=false,badbit=falseβgood()=false,fail()=false,bad()=false,eof()=true,operator bool=true,operator!=falseeofbit=true,failbit=false,badbit=trueβgood()=false,fail()=true,bad()=true,eof()=true,operator bool=false,operator!=trueeofbit=true,failbit=true,badbit=falseβgood()=false,fail()=true,bad()=false,eof()=true,operator bool=false,operator!=trueeofbit=true,failbit=true,badbit=trueβgood()=false,fail()=true,bad()=true,eof()=true,operator bool=false,operator!=true
shoutout to http://cppreference.com for the source/version, dated 2024.06.10, and this was std::basic_ios::bad(3) β mwah, bye bestie! πβ¨π«Ά
π¦ 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