C++ noboolalpha Manipulator

Beginner
5 min read
Updated: Nov 2026
3 examples
iostream

Definition

In C++, noboolalpha is a manipulator that turns the boolalpha setting off. After it, a bool is printed as 1 or 0 again.

This is also the default state of a new stream, so you only need noboolalpha to undo an earlier boolalpha. 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::noboolalpha into the stream after you have used boolalpha.

C++
std::cout << std::boolalpha << true;      // true
std::cout << std::noboolalpha << true;    // 1
CallWhat it does
std::cout << std::noboolalphaPrints bools as 1 and 0 from now on.
std::cout << std::boolalpha << b << std::noboolalphaUses the word form for one value, then switches back.
std::cin >> std::noboolalpha >> flagReads 0 or 1 into a bool.

New streams already start with noboolalpha, so you will rarely need it at the start of a program.

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

Parameters

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

C++ Examples

Example 1 — Turn boolalpha Off Again

Print the same value in word mode and then in number mode.

C++
#include <iostream>

int main() {
    bool ok = true;

    std::cout << std::boolalpha << ok << '\n';
    std::cout << std::noboolalpha << ok << '\n';
    return 0;
}

How It Works

  1. std::boolalpha switches to word mode, so the first line shows true.
  2. std::noboolalpha switches back in the middle of the chain.
  3. The second line prints the same variable, but now as the number 1.

Example 2 — Use Words for One Value Only

Turn on boolalpha just for one item and turn it off straight after.

C++
#include <iostream>

int main() {
    bool a = true;
    bool b = false;

    std::cout << "a = " << std::boolalpha << a << std::noboolalpha
              << ", b = " << b << '\n';
    return 0;
}

How It Works

  1. a is printed while boolalpha is on, so it appears as true.
  2. noboolalpha follows at once and turns the word mode off.
  3. b is printed in number mode, so you see 0 instead of false.

Example 3 — Read 0 and 1 into Bools

noboolalpha is the normal mode for input: digits are accepted.

C++
#include <iostream>
#include <sstream>

int main() {
    std::istringstream in("1 0");
    bool x = false;
    bool y = true;

    in >> std::noboolalpha >> x >> y;

    std::cout << std::boolalpha;
    std::cout << "x = " << x << ", y = " << y << '\n';
    return 0;
}

How It Works

  1. noboolalpha makes >> read a bool from the digits 0 or 1.
  2. 1 becomes true in x, and 0 becomes false in y, even though y started as true.
  3. The output uses boolalpha only to make the results easy to read.

Frequently Asked Questions

It turns off boolalpha, so bool values are printed as 1 and 0 again.
Yes. A new stream already prints bools as 1 and 0, so noboolalpha only undoes an earlier boolalpha.
boolalpha prints true and false. noboolalpha prints 1 and 0.
Yes. It makes cin expect 0 or 1 for a bool. The words true and false are then not accepted.
Yes. cout.unsetf(std::ios::boolalpha) does the same job as cout << std::noboolalpha.

Next: noshowbase

Stop printing the 0x and 0 base prefixes.

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

8 people found this page helpful