C++ noshowbase Manipulator

Beginner
5 min read
Updated: Nov 2026
3 examples
iostream

Definition

In C++, noshowbase turns off the showbase setting. After it, hex numbers print without 0x and octal numbers print without the leading 0.

This is the normal state of a stream. Use noshowbase to undo an earlier showbase, or to be sure that no prefix appears. 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::noshowbase into the stream.

C++
std::cout << std::hex << std::showbase << 255;     // 0xff
std::cout << std::noshowbase << 255;               // ff
CallWhat it does
std::cout << std::noshowbaseTurns the prefix off.
std::cout << std::hex << std::noshowbase << 255Prints ff.
std::cout << std::oct << std::noshowbase << 8Prints 10.

Turning the prefix off is useful when you add your own text in front, such as # for a colour.

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

Parameters

ParameterDescription
strThe stream. It is passed in for you when you write cout << noshowbase. 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 noshowbase.

C++ Examples

Example 1 — Remove the 0x Prefix

Turn the prefix on, print, turn it off, and print again.

C++
#include <iostream>

int main() {
    std::cout << std::hex << std::showbase << 255 << '\n';
    std::cout << std::noshowbase << 255 << '\n';
    return 0;
}

How It Works

  1. With hex and showbase, the first line is 0xff.
  2. noshowbase turns only the prefix off.
  3. The base is still 16, so the second line prints ff.

Example 2 — noshowbase with Octal Numbers

The leading zero of octal numbers disappears too.

C++
#include <iostream>

int main() {
    std::cout << std::oct << std::showbase << 8 << ' ';
    std::cout << std::noshowbase << 8 << '\n';
    return 0;
}

How It Works

  1. In octal, 8 is written 10. With showbase a leading zero is added: 010.
  2. noshowbase comes next in the same chain and removes the prefix.
  3. The second 8 prints as 10. The reader must know that the numbers are in base 8.

Example 3 — Build a Colour Code with Your Own Prefix

Print three hex bytes after a #. The automatic 0x prefix would be wrong here.

C++
#include <iostream>

int main() {
    std::cout << '#' << std::noshowbase << std::hex
              << 171 << 205 << 239 << '\n';
    return 0;
}

How It Works

  1. 171, 205, and 239 are the values of the three colour parts.
  2. std::hex prints each of them as two hex digits: ab, cd, and ef.
  3. noshowbase makes sure that no 0x is printed in front of each part, so the result is the clean text #abcdef.

Frequently Asked Questions

It turns off the base prefix, so hex numbers print without 0x and octal numbers without a leading 0.
Yes. A new stream does not show the prefix, so noshowbase is needed only to undo showbase.
No. It only removes the prefix. Use std::dec to go back to decimal.
When you add your own prefix, such as # for a colour, or when you print a plain hex string like a hash or an id.
cout.unsetf(std::ios::showbase) has the same effect.

Next: noshowpoint

Hide a needless decimal point and trailing zeros.

noshowpoint 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.

9 people found this page helpful