std::resetiosflags(3)

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

πŸ’… std::resetiosflags(3) β€” C++ Standard Libary πŸ’…

std::resetiosflags β€” yep, the NAME is literally std::resetiosflags; that's the whole name, bestie. Iconic behavior, minimal branding.


πŸ¦‹ Synopsis πŸ¦‹

Defined in header <iomanip>:

/*unspecified*/ resetiosflags( std::ios_base::fmtflags mask );

When you use it in an expression like out << resetiosflags(mask) or in >> resetiosflags(mask), it clears all format flags of the stream out or in as specified by the mask. It's giving "clean slate" energy, fr fr.


πŸ“ Parameters πŸ“

  • mask β€” bitmask of the flags to clear. That's the whole parameter. Slay.

✨ Return value ✨

An object of unspecified type such that:

  • if out is an object of type std::basic_ostream<CharT, Traits>, the expression
out << resetiosflags(mask)
  • has type std::basic_ostream<CharT, Traits>&
  • has value out
  • behaves as if it called f(out, mask)
  • if in is an object of type std::basic_istream<CharT, Traits>, the expression
in >> resetiosflags(mask)
  • has type std::basic_istream<CharT, Traits>&
  • has value in
  • behaves as if it called f(in, mask)

where the function f is defined as:

void f(std::ios_base& str, std::ios_base::fmtflags mask)
{
    // reset specified flags
    str.setf(ios_base::fmtflags(0), mask);
}
The return type is literally unspecified β€” do not try to name it, bestie. The vibe is "trust the manipulator," not "collect the type." πŸ™ˆ

πŸŽ€ Example πŸŽ€

The page says // Run this code β€” so run it, bestie:

#include <iomanip>
#include <iostream>
#include <sstream>

int main()
{
    std::istringstream in("10 010 10 010 10 010");
    int n1, n2;

    in >> std::oct >> n1 >> n2;
    std::cout << "Parsing \"10 010\" with std::oct gives: " << n1 << ' ' << n2 << '\n';

    in >> std::dec >> n1 >> n2;
    std::cout << "Parsing \"10 010\" with std::dec gives: " << n1 << ' ' << n2 << '\n';

    in >> std::resetiosflags(std::ios_base::basefield) >> n1 >> n2;
    std::cout << "Parsing \"10 010\" with autodetect gives: " << n1 << ' ' << n2 << '\n';
}

🌈 Output 🌈

Parsing "10 010" with std::oct gives: 8 8
Parsing "10 010" with std::dec gives: 10 10
Parsing "10 010" with autodetect gives: 10 8

🧚 Defect reports 🧚

The following behavior-changing defect reports were applied retroactively to previously published C++ standards:

  • DR LWG 183, applied to C++98 β€” behavior as published: resetiosflags could only be used with streams of type std::ostream or std::istream. Correct behavior: usable with any character stream. Glow-up confirmed. πŸ’–

πŸ‘‘ See also πŸ‘‘

  • setf β€” sets specific format flag; public member function of std::ios_base.
  • setiosflags β€” sets the specified ios_base flags; function.

With love from cppreference.com, version 2024.06.10, page std::resetiosflags(3) πŸ’–

πŸ“¦ where this page comes from