// Example to illustrate formatting of decimal (floating point) values // // illustrates field widths, justification, and fill characters // also illustrates manipulator versions of decimal point formatting #include using namespace std; void PrintData(int x, double y); int main() { int a; double b; cout << "Enter an integer: "; cin >> a; cout << "Enter a double: "; cin >> b; cout << "\n"; PrintData(a,b); cout << "\nSetting flags: fixed, showpoint, and left justify\n"; cout << "Setting precision to 5 places\n"; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.setf(ios::left); cout.precision(5); PrintData(a,b); cout << "\nSetting flags: scientific, right justify\n"; cout << "Setting precision to 1 place\n"; cout.setf(ios::scientific); cout.setf(ios::right); cout.precision(1); PrintData(a,b); cout << "\nSetting fill character to '.'\n"; cout << "Setting flag: showpos\n"; cout.setf(ios::showpos); cout.fill('.'); PrintData(a,b); cout << "\nSee ya!\n"; } void PrintData(int x, double y) // uses width() member function to specify field widths { cout.width(15); cout << x; cout.width(25); cout << y; cout.width(30); cout << "Hello, World"; cout << '\n'; }