std::showpo...d::noshowpos(3)
π 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. π
- Enables the
showposflag in the streamstras if by callingstr.setf(std::ios_base::showpos)π - Disables the
showposflag in the streamstras if by callingstr.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 specifiedios_baseflags (function) π§Ήsetiosflagsβ sets the specifiedios_baseflags (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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms