Namespaces
Variants

std:: boolalpha, std:: noboolalpha

From cppreference.net
< cpp ‎ | io ‎ | manip
Input/output manipulators
Floating-point formatting
Integer formatting
Boolean formatting
boolalpha noboolalpha
Field width and fill control
Other formatting
Whitespace processing
Output flushing
Status flags manipulation
Time and money I/O
(C++11)
(C++11)
(C++11)
(C++11)
Quoted manipulator
(C++14)
定義於ヘッダー <ios>
std:: ios_base & boolalpha ( std:: ios_base & str ) ;
(1)
std:: ios_base & noboolalpha ( std:: ios_base & str ) ;
(2)
1) ストリーム str boolalpha フラグを有効にする。これは str. setf ( std:: ios_base :: boolalpha ) を呼び出した場合と同様の効果を持つ。
2) ストリーム str 内の boolalpha フラグを無効化します。これは str. unsetf ( std:: ios_base :: boolalpha ) を呼び出した場合と同様の効果があります。

std::boolalpha はI/Oマニピュレータであるため、 out << std :: boolalpha のような式で呼び出すことができます( out std::basic_ostream 型の場合)。また、 in >> std :: boolalpha のような式でも呼び出せます( in std::basic_istream 型の場合)。

目次

パラメータ

str - 参照するI/Oストリーム

戻り値

str (操作後のストリームへの参照)。

#include <iostream>
#include <sstream>
int main()
{
    // boolalpha 出力
    std::cout << "default true: " << true << '\n'
              << "default false: " << false << '\n'
              << std::boolalpha 
              << "boolalpha true: " << true << '\n'
              << "boolalpha false: " << false << '\n'
              << std::noboolalpha 
              << "noboolalpha true: " << true << '\n'
              << "noboolalpha false: " << false << '\n';
    // boolalpha 解析
    bool b1, b2;
    std::istringstream is("true false");
    is >> std::boolalpha >> b1 >> b2;
    std::cout << '"' << is.str() << "\" parsed as: "
              << std::boolalpha << b1 << ' ' << b2 << '\n';
}

出力:

default true: 1
default false: 0
boolalpha true: true
boolalpha false: false
noboolalpha true: 1
noboolalpha false: 0
"true false" parsed as: true false

関連項目

指定された ios_base フラグをクリアする
(関数)
指定された ios_base フラグを設定する
(関数)
ブーリアン値 true および false の名前として使用する文字列を提供する
( std::numpunct<CharT> の仮想保護メンバ関数)