C++ noshowpos Manipulator

Beginner
5 min read
Updated: Nov 2026
3 examples
iostream

Definition

In C++, noshowpos turns off showpos. After it, positive numbers print without a plus sign again, which is the normal way.

You often use it to show one value with a sign and the following values without. It comes from <ios>, which <iostream> includes.

This is a manipulator. You do not call it on its own. You send it into a stream with << or >>, and it changes how that stream behaves from then on (or does one small job, like ending a line).

Syntax

Put std::noshowpos into the stream.

C++
std::cout << std::showpos << 5;     // +5
std::cout << std::noshowpos << 5;   // 5
CallWhat it does
std::cout << std::noshowposPositive numbers have no plus sign.
std::cout << std::showpos << d << std::noshowposSigns for one value, then back to normal.
std::cout << std::noshowpos << 1.5Prints 1.5.

New streams already start with noshowpos. It only matters after showpos was used.

Library declarations
C++
ios_base& noshowpos(ios_base& str);

Parameters

ParameterDescription
strThe stream. It is passed in for you when you write cout << noshowpos. You never write this argument yourself.

Return Value

Return ValueDescription
ios_base&A reference to the same stream, so you can keep chaining << or >> after noshowpos.

C++ Examples

Example 1 — Turn Off the Plus Sign

Print the same number twice, once for each mode.

C++
#include <iostream>

int main() {
    std::cout << std::showpos << 1 << ' ';
    std::cout << std::noshowpos << 1 << '\n';
    return 0;
}

How It Works

  1. showpos is on first, so the first 1 appears as +1.
  2. noshowpos follows in the second statement and turns the plus sign off.
  3. The second 1 prints as a plain 1.

Example 2 — Sign for the Change, Plain Total

A report that shows the change with a sign and the total without one.

C++
#include <iostream>

int main() {
    int delta = 5;
    int total = 105;

    std::cout << "change: " << std::showpos << delta
              << std::noshowpos << ", total: " << total << '\n';
    return 0;
}

How It Works

  1. showpos is turned on just before delta, so it prints as +5.
  2. noshowpos is put in straight after it.
  3. total is then printed in the normal way: 105, with no plus sign.

Example 3 — noshowpos with Decimal Numbers

The setting works for floating-point numbers in the same way.

C++
#include <iostream>

int main() {
    std::cout << std::showpos << 1.5 << ' ';
    std::cout << std::noshowpos << 1.5 << ' ';
    std::cout << -1.5 << '\n';
    return 0;
}

How It Works

  1. With showpos, 1.5 prints as +1.5.
  2. After noshowpos, the same 1.5 prints with no sign.
  3. The last number -1.5 is negative. Its minus sign stays: noshowpos never removes it.

Frequently Asked Questions

It turns off the plus sign for positive numbers that showpos switched on.
Yes. A stream does not print a plus sign unless you turn showpos on.
No. Negative numbers always keep their minus sign.
Yes. Put showpos before the value and noshowpos right after it.
cout.unsetf(std::ios::showpos) does the same thing.

Next: noskipws

Read spaces and new lines like normal characters.

noskipws tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful