C++/Data Type/bool output

Материал из C\C++ эксперт
Перейти к: навигация, поиск

Booleans in both formats

<source lang="cpp">

  1. include <iostream>
  2. include <iomanip>

using namespace std; int main() {

 cout << "Default format: " << 123.123456789 << endl;
 cout << "Booleans in both formats: ";
 cout << true << " " << false << " " << boolalpha
      << true << " " << false << "\n\n";
 return 0;

}


 </source>


Clear the boolalpha flag

<source lang="cpp">

  1. include <iostream>

using namespace std; int main() {

 cout.setf(ios::boolalpha);
 cout << true << endl;;
 cout.unsetf(ios::boolalpha);
 cout << true << endl;;
 return 0;

}


 </source>


Demonstrate the setf() and unsetf() functions.

<source lang="cpp">

  1. include <iostream>

using namespace std; int main() {

 // Set the boolalpha flag on cout.
 cout.setf(ios::boolalpha);
 cout << true << endl;;
 // clear the boolalpha flag.
 cout.unsetf(ios::boolalpha);
 cout << true << endl;;
 return 0;

}


 </source>


Set the boolalpha flag on cout

<source lang="cpp">

  1. include <iostream>

using namespace std; int main() {

 cout.setf(ios::boolalpha);
 cout << true << endl;;
 cout.unsetf(ios::boolalpha);
 cout << true << endl;;
 return 0;

}


 </source>