function
<ios> <iostream>

std::showpos

ios_base& showpos (ios_base& str);
Show positive signs
Sets the showpos format flag for the str stream.

When the showpos format flag is set, a plus sign (+) precedes every non-negative numerical value inserted into the stream (including zeros).

This flag can be unset with the noshowpos manipulator.

For standard streams, the showpos flag is not set on initialization.

Parameters

str
Stream object whose format flag is affected.
Because this function is a manipulator, it is designed to be used alone with no arguments in conjunction with the insertion (<<) and extraction (>>) operations on streams (see example below).

Return Value

Argument str.

Example

1
2
3
4
5
6
7
8
9
10
11
// modify showpos flag
#include <iostream>     // std::cout, std::showpos, std::noshowpos

int main () {
  int p = 1;
  int z = 0;
  int n = -1;
  std::cout << std::showpos   << p << '\t' << z << '\t' << n << '\n';
  std::cout << std::noshowpos << p << '\t' << z << '\t' << n << '\n';
  return 0;
}

Possible output:
+1      +0      -1
1       0       -1


Data races

Modifies str. Concurrent access to the same stream object may cause data races.

Exception safety

Basic guarantee: if an exception is thrown, str is in a valid state.

See also