std::basic_ios::rdstate(3)

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

πŸ’… std::basic_ios::rdstate(3) πŸ’…

okay so this page is from the C++ Standard Libary manual, and it's giving β€œtiny but iconic stream-state check” energy. Let's get into it, bestie πŸ’–


πŸŽ€ NAME πŸŽ€

std::basic_ios::rdstate β€” literally std::basic_ios::rdstate. That's the name. No notes. iconic πŸ’…


✨ Synopsis ✨

iostate rdstate() const;

Returns the current stream error state, fr fr 😭


🫢 Parameters 🫢

(none) β€” literally none, bestie. nothing to pass, nothing to stress about πŸ’€


πŸ’– Return value πŸ’–

The return value is the current stream error state. It's a bitmask type and can be a combination of the following constants:

  • 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

like, it can be more than one vibe at once, iykyk 🌈


🌸 Example 🌸

// Run this code

#include <iostream>
#include <sstream>

int main()
{
    std::ostringstream stream;

    if (stream.rdstate() == std::ios_base::goodbit)
        std::cout << "stream state is goodbit\n";

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

    // check state is exactly eofbit (no failbit and no badbit)
    if (stream.rdstate() == std::ios_base::eofbit)
        std::cout << "stream state is eofbit\n";
}

Output:

stream state is goodbit
stream state is eofbit

πŸ” See also πŸ”

  • setstate β€” sets state flags (public member function)
  • clear β€” modifies state flags (public member function)

okay that's the whole page, bestie 🫢 β€” source: http://cppreference.com, version/date: 2024.06.10, page: std::basic_ios::rdstate(3). periodt ✨

πŸ“¦ where this page comes from