Specifying Boolean Format, boolalpha - C++ File Stream

C++ examples for File Stream:cout

Description

Specifying Boolean Format, boolalpha

Demo Code

#include <iostream>
#include <iomanip>
int main(int argc, const char *argv[]) {
    bool booleanValue = true;

    // display default true booleanValue
    std::cout << "booleanValue is " << booleanValue << std::endl;

    // display booleanValue after using boolalpha
    std::cout << "booleanValue (after using boolalpha) is " << std::boolalpha
              << booleanValue << std::endl
              << std::endl;/*from   w  w w .j av a  2s . com*/

    std::cout << "switch booleanValue and use noboolalpha" << std::endl;
    booleanValue = false;
    std::cout << std::noboolalpha << std::endl;

    // display default false booleanValue after using noboolalpha
    std::cout << "booleanValue is " << booleanValue << std::endl;

    // display booleanValue after using boolalpha again
    std::cout << "booleanValue (after using boolalpha) is " << std::boolalpha
              << booleanValue << std::endl;

    return 0;
}

Result


Related Tutorials