function
<ios> <iostream> <iostream>

std::boolalpha

ios_base& boolalpha (ios_base& str);
Alphanumerical bool values
Sets the boolalpha format flag for the str stream.

When the boolalpha format flag is set, bool values are inserted/extracted by their textual representation: either true or false, instead of integral values.

This flag can be unset with the noboolalpha manipulator.

For standard streams, the boolalpha 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
// modify boolalpha flag
#include <iostream>     // std::cout, std::boolalpha, std::noboolalpha

int main () {
  bool b = true;
  std::cout << std::boolalpha << b << '\n';
  std::cout << std::noboolalpha << b << '\n';
  return 0;
}

Output:
true
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