C++ ios Library - Boolalpha Function


Advertisements

Description

It is used to 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.

Declaration

Following is the declaration for std::boolalpha function.

ios_base& boolalpha (ios_base& str);

Parameters

str − Stream object whose format flag is affected.

Return Value

It returns Argument str.

Exceptions

Basic guarantee − if an exception is thrown, str is in a valid state.

Data races

It modifies str. Concurrent access to the same stream object may cause data races.

Example

In below example explains about std::boolalpha function.

#include <iostream>     

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

Let us compile and run the above program, this will produce the following result −

true
1
ios.htm
Advertisements