std::basic_ios::setstate(3)

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

✨ NAME ✨

hii bestie!! πŸ’– welcome to std::basic_ios::setstate(3) from the C++ Standard Libary (yes, that spelling, we are respecting the source, periodt πŸ’…).

std::basic_ios::setstate - std::basic_ios::setstate

okay so the name is literally the same thing twice β€” iconic redundancy, no cap πŸ’€.

🌸 Synopsis 🌸

void setstate( iostate state );

Sets the stream error flags state in addition to currently set flags. Essentially it calls clear(rdstate() | state). May throw an exception, so don’t act brand new about it 😭.

πŸ’– Parameters πŸ’–

state is the stream error state flags to set. It can be a combination of the following constants, bestie:

Constant Explanation:

  • goodbit β€” no error
  • badbit β€” irrecoverable stream error
  • failbit β€” input/output operation failed (formatting or extraction error)
  • eofbit β€” associated input sequence has reached end-of-file

✨ Return value ✨

(none) β€” literally no return value, she gives nothing back and that’s on periodt πŸ’….

πŸŽ€ Example πŸŽ€

Run this code, bestie:

#include <iostream>
#include <sstream>

int main()
{
    std::ostringstream stream;

    if (!stream.fail())
        std::cout << "stream is not fail\n";

    stream.setstate(std::ios_base::failbit);

    if (stream.fail())
        std::cout << "now stream is fail\n";

    if (!stream.good())
        std::cout << "and stream is not good\n";
}

Output:

stream is not fail
now stream is fail
and stream is not good

πŸ¦‹ See also πŸ¦‹

  • rdstate β€” returns state flags (public member function)
  • clear β€” modifies state flags (public member function)

xoxo, your fave unix bestie πŸ’– β€” source/version: http://cppreference.com; date: 2024.06.10; page: std::basic_ios::setstate(3).

πŸ“¦ where this page comes from