std::fpos::state(3)

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

✨ std::fpos::state(3) ✨ β€” C++ Standard Libary

🌸 NAME 🌸

std::fpos::state β€” std::fpos::state. That’s the name, and honestly? iconic. πŸ’…

πŸ¦‹ Synopsis πŸ¦‹

State state() const;    (1)
void state( State st ); (2)

This little duo manages the file position state. 🫢

  1. Returns the value of the file position state.
  2. Replaces the file position state with the value of st.

Real talk: for the specializations of std::fpos that are used in the standard library, State is always std::mbstate_t. No cap. πŸ’–

πŸ’… Parameters πŸ’…

  • st β€” new value for the state.

πŸŽ€ Return value πŸŽ€

  1. The current value of the fpos state.
  2. (none)

πŸ¦‹ Example πŸ¦‹

// Run this code

#include <cwchar>
#include <iostream>
#include <sstream>

int main()
{
    std::istringstream s("test");
    std::mbstate_t st = s.tellg().state();

    if (std::mbsinit(&st))
        std::cout << "The stream is in the initial shift state\n";
}

Output:

The stream is in the initial shift state

πŸ’€ Defect reports πŸ’€

The following behavior-changing defect reports were applied retroactively to previously published C++ standards. Yes, the lore goes back. 😭

  • DR: LWG 441
    • Applied to: C++98
    • Behavior as published: overload (1) was not declared const (it is const in the synopsis)
    • Correct behavior: added const

πŸ‘€ See also πŸ‘€

  • mbstate_t β€” conversion state information necessary to iterate multibyte character strings (class).

🌈 That’s the whole page, bestie! Source: http://cppreference.com Β· version/date: 2024.06.10 Β· std::fpos::state(3) and we are so done. πŸ’–πŸ‘‘
πŸ“¦ where this page comes from