Wednesday, December 27, 2017

C++98: The boolalpha and noboolalpha Manipulators on cout

The boolalpha manipulator changes the way Boolean values are output to cout. Here is an example:

#include <iostream>

int main()
{
  std::cout << true  << " "; // 1
  std::cout << false << " "; // 0

  std::cout << std::boolalpha;

  std::cout << true  << " "; // true
  std::cout << false << " "; // false

  std::cout << std::noboolalpha;

  std::cout << true  << " "; // 1
  std::cout << false << " "; // 0

  std::cout << std::endl;
  return 0;
}
// Output: 1 0 true false 1 0
Reference: Josuttis, Nicolai M., The C++ Standard Library: A Tutorial and Reference. New York: Addison-Wesley, 1999, p. 617.

No comments:

Post a Comment