C++/Data Type/bool output
Содержание
Booleans in both formats
<source lang="cpp">
- 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;
}
</source>
Clear the boolalpha flag
<source lang="cpp">
- 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">
- 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">
- include <iostream>
using namespace std; int main() {
cout.setf(ios::boolalpha); cout << true << endl;; cout.unsetf(ios::boolalpha); cout << true << endl;; return 0;
}
</source>