C++ examples for Language Basics:Console
Flag | Meaning |
---|---|
ios::fixed | Always show the decimal point with six digits after the decimal point. This flag takes precedence if it's set with the ios::showpoint flag. |
ios::scientific | Use exponential display in the output. |
ios::showpoint | Always display a decimal point and six significant digits total. |
ios::showpos | Display a leading + sign when the number is positive. |
ios::left | Left-justify the output. |
ios::right | Right-justify the output. |
To combine the flags.
cout << setiosflags(ios::dec | ios::fixed | ios::showpoint);
#include <iostream> #include <iomanip> using namespace std; int main()//from w w w. ja v a 2s. c o m { cout << "|" << 5 <<"|"; cout << "|" << setw(4) << 5 << "|"; cout << "|" << setw(4) << 56829 << "|"; cout << "|" << setw(5) << setiosflags(ios::fixed) << setprecision(2) << 5.26 << "|"; cout << "|" << setw(5) << setiosflags(ios::fixed) << setprecision(2) << 5.267 << "|"; cout << "|" << setw(5) << setiosflags(ios::fixed) << setprecision(2) << 53.264 << "|"; cout << "|" << setw(5) << setiosflags(ios::fixed) << setprecision(2) << 534.264 << "|"; cout << "|" << setw(5) << setiosflags(ios::fixed) << setprecision(2) << 534. << "|"; return 0; }