C++/Data Type/bool output

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

Booleans in both formats

  
#include <iostream>
#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;
}


Clear the boolalpha flag

  
#include <iostream>
using namespace std;
int main()
{
  cout.setf(ios::boolalpha);
  cout << true << endl;;
  cout.unsetf(ios::boolalpha);
  cout << true << endl;;
  return 0;
}


Demonstrate the setf() and unsetf() functions.

  
#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;
}


Set the boolalpha flag on cout

  
#include <iostream>
using namespace std;
int main()
{
  cout.setf(ios::boolalpha);
  cout << true << endl;;
  cout.unsetf(ios::boolalpha);
  cout << true << endl;;
  return 0;
}