C++/Data Type/bool output


Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /var/www/cppe.ru/www/includes/parser/Preprocessor_DOM.php on line 803

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/vendor/mediawiki/at-ease/src/Functions.php on line 48
Материал из 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;
}