std::showpo...d::noshowpos(3)

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

πŸ’… NAME πŸ’…

std::showpos, std::noshowpos β€” ok so these are literally the twin manipulators that turn the plus sign on and off in your output πŸŽ€ (breaking news from the C++ Standard Library, bestie, and yes I folded the manual name in right there, you're welcome ✨)


✨ SYNOPSIS ✨

Defined in header <ios>:

std::ios_base& showpos( std::ios_base& str );   (1)
std::ios_base& noshowpos( std::ios_base& str ); (2)

So what do they actually do? They enable or disable the display of the plus sign '+' in non-negative integer output 🫢

And bestie, hear me: it has no effect on input. None. Zero. Nada. πŸ™ˆ

  1. Enables the showpos flag in the stream str as if by calling str.setf(std::ios_base::showpos) πŸ‘‘
  2. Disables the showpos flag in the stream str as if by calling str.unsetf(std::ios_base::showpos) πŸ’€

Also!! This is an I/O manipulator, meaning it may be called with an expression such as out << std::showpos for any out of type std::basic_ostream, or with an expression such as in >> std::showpos for any in of type std::basic_istream πŸ¦‹


🌸 PARAMETERS 🌸

  • str β€” reference to I/O stream. That's it. That's the whole parameter list. Iconic minimalism πŸ’…

πŸŽ€ RETURN VALUE πŸŽ€

str β€” the reference to the stream after manipulation, handed right back to you like a bestie returning your lip gloss 🫢


⭐ EXAMPLE ⭐

Run this code, no cap:

#include <iostream>

int main()
{
    std::cout
        << "showpos: " << std::showpos << 42 << ' ' << 3.14 << ' ' << 0 << '\n'
        << "noshowpos: " << std::noshowpos << 42 << ' ' << 3.14 << ' ' << 0 << '\n';
}

Output:

showpos: +42 +3.14 +0
noshowpos: 42 3.14 0

See how the plus signs just appear? Ate. πŸ”₯


πŸ’œ SEE ALSO πŸ’œ

  • resetiosflags β€” clears the specified ios_base flags (function) 🧹
  • setiosflags β€” sets the specified ios_base flags (function) ✨

That's the whole page, bestie β€” freshly served from http://cppreference.com, version 2024.06.10, and yeah the date on this one is 2024.06.10 too. Go forth and plus-sign your integers πŸ’–πŸŒˆπŸ¦‹

πŸ“¦ where this page comes from