Printing Boolean Values in C++ Last Updated : 27 May, 2024 Comments Improve Suggest changes Like Article Like Report 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:bool flag1= 1bool flag2= 0Output:flag1: trueflag2: falsePrint 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 boolalphacout << std::noboolalpha; // Disable boolalphastd::boolalpha is used to set the output stream to print boolean values as true or false.std::noboolalpha is used to revert the output stream to it's default behavior.C++ Program to Print Boolean Values The following program illustrates how we can print the boolean values in a more readable format using the boolalpha flag in C++: C++ // C++ Program to Print Boolean Values #include <iostream> using namespace std; int main() { // Initialize the boolean values bool flag1 = true; bool flag2 = false; cout<<"Booelan values with boolalpha flag enabled:"<<endl; // Enable boolalpha cout << boolalpha; cout << "flag1: " << flag1 << endl; cout << "flag2: " << flag2 << endl; cout<<"Booelan values with boolalpha flag disabled:"<<endl; // Disable boolalpha cout << noboolalpha; cout << "flag1: " << flag1 << endl; cout << "flag2: " << flag2 << endl; return 0; } OutputBooelan values with boolalpha flag enabled: flag1: true flag2: false Booelan values with boolalpha flag disabled: flag1: 1 flag2: 0 Time Complexity: O(1)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Printing Boolean Values in C++ S satwiksuman Follow Improve Article Tags : C++ Programs C++ cpp-data-types CPP-Output cpp-manipulators CPP Examples +2 More Practice Tags : CPP Similar Reads C++ Program For Boolean to String Conversion In this article, we will see how to convert a boolean to a string using a C++ program. In boolean algebra, there are only two values 0 and 1 which represent False and True. Thus, boolean to string conversion can be stated as: Boolean -> String 1 -> True0 -> False Example: Input: 1 Output: T 2 min read Maximum value of unsigned int in C++ In this article, we will discuss the maximum value of unsigned int in C++. Unsigned int data type in C++ is used to store 32-bit integers.The keyword unsigned is a data type specifier, which only represents non-negative integers i.e. positive numbers and zero. Some properties of the unsigned int dat 2 min read How to Print an Array in C++? In C++, an array is a fixed-size linear data structure that stores a collection of elements of the same type in contiguous memory locations. In this article, we will learn how to print an array in C++. For Example, Input: array = {10, 20, 30, 40, 50}Output: Array Elements: 10 20 30 40 50Printing Arr 2 min read Maximum value of unsigned char in C++ In this article, we will discuss the maximum value of unsigned char data type in C++. Some properties of the unsigned char data type are: Being an unsigned data type, it can store only positive values.Unsigned char data type in C++ is used to store 8-bit characters.A maximum value that can be stored 2 min read Managing Console I/O operations in C++ Every program takes some data as input and generates processed data as an output following the familiar input process output cycle. It is essential to know how to provide the input data and present the results in the desired form. The use of the cin and cout is already known with the operator > 4 min read Like