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)
Défini dans l'en-tête <ios>
std:: ios_base & boolalpha ( std:: ios_base & str ) ;
(1)
std:: ios_base & noboolalpha ( std:: ios_base & str ) ;
(2)
1) Active le drapeau boolalpha dans le flux str comme en appelant str. setf ( std:: ios_base :: boolalpha ) .
2) Désactive le drapeau boolalpha dans le flux str comme en appelant str. unsetf ( std:: ios_base :: boolalpha ) .

std::boolalpha est un manipulateur d'E/S, donc il peut être appelé avec une expression telle que out << std :: boolalpha pour tout out de type std::basic_ostream ou avec une expression telle que in >> std :: boolalpha pour tout in de type std::basic_istream .

Table des matières

Paramètres

str - référence au flux d'E/S

Valeur de retour

str (référence au flux après manipulation).

Exemple

#include <iostream>
#include <sstream>
int main()
{
    // Sortie boolalpha
    std::cout << "true par défaut : " << true << '\n'
              << "false par défaut : " << false << '\n'
              << std::boolalpha 
              << "boolalpha true : " << true << '\n'
              << "boolalpha false : " << false << '\n'
              << std::noboolalpha 
              << "noboolalpha true : " << true << '\n'
              << "noboolalpha false : " << false << '\n';
    // Analyse boolalpha
    bool b1, b2;
    std::istringstream is("true false");
    is >> std::boolalpha >> b1 >> b2;
    std::cout << '"' << is.str() << "\" analysé comme : "
              << std::boolalpha << b1 << ' ' << b2 << '\n';
}

Sortie :

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

Voir aussi

efface les indicateurs spécifiés de ios_base
(fonction)
définit les indicateurs spécifiés de ios_base
(fonction)
fournit la chaîne à utiliser comme nom des valeurs booléennes true et false
(fonction membre protégée virtuelle de std::numpunct<CharT> )