std::setiosflags(3)

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

πŸ’– NAME πŸ’–

std::setiosflags - std::setiosflags

okay bestie, you're on the std::setiosflags(3) page from the C++ Standard Libary (that's the header's spelling, iykyk πŸ’€). This is the thing that sets format flags on a stream, and we're gonna get you through it without missing a single detail βœ¨πŸ’…


✨ Synopsis ✨

Defined in header <iomanip> πŸŽ€

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

When used in an expression out << setiosflags(mask) or in the expression in >> setiosflags(mask), it sets all format flags of the stream out or in as specified by the mask ⭐

bestie, the return type is literally /*unspecified*/ β€” that's the whole vibe the page gives us πŸ’€

🌸 Parameters 🌸

  • mask β€” bitmask of the flags to set. That's your little bundle of flag bits πŸŽ€

πŸ¦‹ Return value πŸ¦‹

An object of unspecified type such that:

  • if out is an object of type std::basic_ostream<CharT, Traits>, the expression out << setiosflags(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 >> setiosflags(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)
{
    // set specified flags
    str.setf(mask);
}

πŸŽ€ Example πŸŽ€

Run this code πŸ‘‡

#include <iomanip>
#include <iostream>

int main()
{
    std::cout << std::resetiosflags(std::ios_base::dec)
              << std::setiosflags(  std::ios_base::hex
                                  | std::ios_base::uppercase
                                  | std::ios_base::showbase) << 42 <<
'\n';
}

⭐ Output ⭐

0X2A

πŸ’€ 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: setiosflags could only be used with streams of type std::ostream or std::istream. Correct behavior: usable with any character stream.

🌈 See also 🌈

  • setf β€” sets specific format flag (public member function of std::ios_base)
  • resetiosflags β€” clears the specified ios_base flags (function)

that's the whole page, bestie 🫢 source: http://cppreference.com; version/date: 2024.06.10 β€” and yes, this was the std::setiosflags(3) manual tea β˜•πŸ’…

πŸ“¦ where this page comes from