C++ true Keyword
Example
Print the value true as a number, and as a word:
bool isCodingFun = true;
cout << isCodingFun << "\n";
cout << boolalpha << isCodingFun;
Definition and Usage
The true keyword is one of the two values a bool can have. The other value is false.
When you print true with cout, it shows 1. To print the word true instead, use boolalpha.
Comparisons also give a boolean value. For example, 5 > 3 is true.
Related Pages
The bool keyword is a data type that can only take the values true or false.
Read more about booleans in our C++ Booleans Tutorial.