Namespaces
Variants

Boolean literals

From ja.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

目次

構文

true (1)
false (2)

説明

ブーリアンリテラルはキーワード true と false です。これらは prvalue であり、型は bool です。

注記

Integral conversions を参照して、 bool から他の型への暗黙変換と、 boolean conversions を参照して、他の型から bool への暗黙変換を確認してください。

キーワード

false , true

例

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

出力:

true
false
1
0

参考文献

  • C++23標準 (ISO/IEC 14882:2024):
  • 5.13.6 ブーリアンリテラル [lex.bool]
  • C++20 標準 (ISO/IEC 14882:2020):
  • 5.13.6 ブーリアンリテラル [lex.bool]
  • C++17規格 (ISO/IEC 14882:2017):
  • 5.13.6 ブーリアンリテラル [lex.bool]
  • C++14標準 (ISO/IEC 14882:2014):
  • 2.13.6 ブーリアンリテラル [lex.bool]
  • C++11標準 (ISO/IEC 14882:2011):
  • 2.13.6 ブーリアンリテラル [lex.bool]
  • C++98標準 (ISO/IEC 14882:1998):
  • 2.13.5 ブーリアンリテラル [lex.bool]

関連項目

Cドキュメント の 定義済みブーリアン定数