Namespaces
Variants

Boolean literals

From cppreference.net
C++ language
General topics
Flow control
Conditional execution statements
Iteration statements (loops)
Jump statements
Functions
Function declaration
Lambda function expression
inline specifier
Dynamic exception specifications ( until C++17* )
noexcept specifier (C++11)
Exceptions
Namespaces
Types
Specifiers
constexpr (C++11)
consteval (C++20)
constinit (C++20)
Storage duration specifiers
Initialization
Expressions
Alternative representations
Literals
Boolean - Integer - Floating-point
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
typedef declaration
Type alias declaration (C++11)
Casts
Memory allocation
Classes
Class-specific function properties
Special member functions
Templates
Miscellaneous

Inhaltsverzeichnis

Syntax

true (1)
false (2)

Erklärung

Die booleschen Literale sind die Schlüsselwörter true und false . Sie sind Prvalues vom Typ bool .

Hinweise

Siehe Ganzzahlige Konvertierungen für implizite Konvertierungen von bool zu anderen Typen und Boolesche Konvertierungen für die impliziten Konvertierungen von anderen Typen zu bool .

Schlüsselwörter

false , true

Beispiel

#include <iostream>
int main()
{
    std::cout << std::boolalpha
              << true << '\n'
              << false << '\n'
              << std::noboolalpha
              << true << '\n'
              << false << '\n';
}

Ausgabe:

true
false
1
0

Referenzen

  • C++23-Standard (ISO/IEC 14882:2024):
  • 5.13.6 Boolesche Literale [lex.bool]
  • C++20-Standard (ISO/IEC 14882:2020):
  • 5.13.6 Boolesche Literale [lex.bool]
  • C++17-Standard (ISO/IEC 14882:2017):
  • 5.13.6 Boolesche Literale [lex.bool]
  • C++14-Standard (ISO/IEC 14882:2014):
  • 2.13.6 Boolesche Literale [lex.bool]
  • C++11-Standard (ISO/IEC 14882:2011):
  • 2.13.6 Boolesche Literale [lex.bool]
  • C++98-Standard (ISO/IEC 14882:1998):
  • 2.13.5 Boolesche Literale [lex.bool]

Siehe auch

C-Dokumentation für Vordefinierte Boolean-Konstanten