![]() |
In C++, a boolean data type can only have two possible values true and false. However, when we print the boolean data types using the standard output streams like cout they are printed as 0 or 1 instead of true or false. In this article, we will learn how to print boolean values in C++ so that true and false are displayed on the output screen instead of 0 or 1. Example Input: Print Boolean ValuesTo print boolean values in a more readable form, we can use the boolalpha flag provided by the Standard Template Library(STL) of C++. Following is the syntax to use the boolalpha flag: Syntaxcout << std::boolalpha; // Enable boolalpha
C++ Program to Print Boolean ValuesThe following program illustrates how we can print the boolean values in a more readable format using the boolalpha flag in C++:
Output Booelan values with boolalpha flag enabled: flag1: true flag2: false Booelan values with boolalpha flag disabled: flag1: 1 flag2: 0 Time Complexity: O(1) |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 8 |