C++ ios :: boolalpha














































C++ ios :: boolalpha



DESCRIPTION: 

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.


ios_base& noboolalpha (ios_base& str);
No alphanumerical bool values
Clears the boolalpha format flag for the str stream.

When the boolalpha format flag is not setbool values are insterted/extracted as integral values (0 and 1) instead of their textual representations: true and false.

This flag can be set with the boolalpha manipulator.

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

Parameters:     

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:

Return the resultant string. 

 

Program 1:

 

#include <iostream>   
  // std::cout, std::boolalpha, std::noboolalpha

int main () {

  bool b = true;

  std::cout << std::boolalpha << b << endl;

  std::cout << std::noboolalpha << b << endl;

  return 0;
}

Output:

true
1

Program 2:

 

#include <iostream>   
  // std::cout, std::boolalpha, std::noboolalpha

int main () {

  bool b = false;

  std::cout << std::noboolalpha << b << endl;

  return 0;
}

Output:

0

Comments