1 / 31

Output Formatting

Output Formatting. Precision. #include < iomanip > ... float grade = 86.1263f; cout.precision (4); cout << grade;. 86.13. Precision. #include < iomanip > ... float grade1 = 86.1263f; float grade2 = 93.1311f; cout.precision (4); cout << grade1 << endl ; ...

Download Presentation

Output Formatting

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Output Formatting

  2. Precision #include <iomanip> ... float grade = 86.1263f; cout.precision(4); cout << grade;

  3. 86.13

  4. Precision #include <iomanip> ... float grade1 = 86.1263f; float grade2 = 93.1311f; cout.precision(4); cout << grade1 << endl; ... cout << grade2 << endl;

  5. 86.1393.13

  6. Width of Output #include <iomanip> ... float grade1 = 86.1243f; float grade2 = 93.1311f; cout.width(10); cout << grade1 << endl; ... cout << grade2 << endl;

  7. 86.124393.1311

  8. ios flags • Statement Form • cout.setf(ios::the_flag); • Available Flags • ios::scientific • ios::fixed • ios::right • ios::left • ios::internal • ios::showpos • ios::showpoint • ios::skipws

  9. ios flags • Statement Form • cout.setf(ios::the_flag); • Available Flags • ios::scientific output in scientific notation • ios::fixed • ios::right • ios::left • ios::internal • ios::showpos • ios::showpoint • ios::skipws

  10. ios flags • Statement Form • cout.setf(ios::the_flag); • Available Flags • ios::scientific output in scientific notation • ios::fixed output in standard notation • ios::right • ios::left • ios::internal • ios::showpos • ios::showpoint • ios::skipws

  11. ios flags • Statement Form • cout.setf(ios::the_flag); • Available Flags • ios::scientific output in scientific notation • ios::fixed output in standard notation • ios::right output right-justified in output field • ios::left • ios::internal • ios::showpos • ios::showpoint • ios::skipws

  12. ios flags • Statement Form • cout.setf(ios::the_flag); • Available Flags • ios::scientific output in scientific notation • ios::fixed output in standard notation • ios::right output right-justified in output field • ios::left output left-justified in output field • ios::internal • ios::showpos • ios::showpoint • ios::skipws

  13. ios flags • Statement Form • cout.setf(ios::the_flag); • Available Flags • ios::scientific output in scientific notation • ios::fixed output in standard notation • ios::right output right-justified in output field • ios::left output left-justified in output field • ios::internal puts space between – or + sign and output • ios::showpos • ios::showpoint • ios::skipws

  14. ios flags • Statement Form • cout.setf(ios::the_flag); • Available Flags • ios::scientific output in scientific notation • ios::fixed output in standard notation • ios::right output right-justified in output field • ios::left output left-justified in output field • ios::internal puts space between – or + sign and output • ios::showposshows + sign • ios::showpoint • ios::skipws

  15. ios flags • Statement Form • cout.setf(ios::the_flag); • Available Flags • ios::scientific output in scientific notation • ios::fixed output in standard notation • ios::right output right-justified in output field • ios::left output left-justified in output field • ios::internal puts space between – or + sign and output • ios::showposshows + sign • ios::showpointshows decimal point with trailing zeros • ios::skipws

  16. ios flags • Statement Form • cout.setf(ios::the_flag); • Available Flags • ios::scientific output in scientific notation • ios::fixed output in standard notation • ios::right output right-justified in output field • ios::left output left-justified in output field • ios::internal puts space between – or + sign and output • ios::showposshows + sign • ios::showpointshows decimal point with trailing zeros • ios::skipwsshows output without whitespace

  17. ios Example #include <iomanip> ... double mole = 602200000000000000000000.0; float grade = 97.153f; cout.setf(ios::scientific); cout << mole << endl; cout.unsetf(ios::scientific); ... cout << grade << endl;

  18. 6.022000e+2397.153

  19. ios Example #include <iomanip> ... float money = 1441.3531f; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); cout << money << endl;

  20. 1441.35

  21. Manipulators setw(int_val) setprecision(int_val) endl flush setfill(char_val)

  22. Manipulators • setw(int_val) • sets output width to int_val spaces • setprecision(int_val) • endl • flush • setfill(char_val)

  23. Manipulators • setw(int_val) • sets output width to int_val spaces • setprecision(int_val) • sets precision from there on out to int_val sig figs • endl • flush • setfill(char_val)

  24. Manipulators • setw(int_val) • sets output width to int_val spaces • setprecision(int_val) • sets precision from there on out to int_val sig figs • endl • puts the cursor at the beginning of the next output line • flush • setfill(char_val)

  25. Manipulators • setw(int_val) • sets output width to int_val spaces • setprecision(int_val) • sets precision from there on out to int_val sig figs • endl • puts the cursor at the beginning of the next output line • flush • flushes the buffer • setfill(char_val)

  26. Manipulators • setw(int_val) • sets output width to int_val spaces • setprecision(int_val) • sets precision from there on out to int_val sig figs • endl • puts the cursor at the beginning of the next output line • flush • flushes the buffer • setfill(char_val) • fills non-output space in a field to char_val

  27. Precision Manipulator #include <iomanip> ... float grade1 = 86.1243f; float grade2 = 93.1311f; cout << setprecision(4) << grade1 << endl; ... cout << grade2 << endl;

  28. 86.1293.13

  29. Width of Output Manipulator #include <iomanip> ... float grade1 = 86.1243f; float grade2 = 93.1311f; float grade3 = 74.4142f; cout << grade1 << endl; cout << setw(10) << grade2 << endl; cout << setfill(‘*’) << setw(10) << grade3 << endl;

  30. 86.1243 93.1311***74.4142

  31. End of Session

More Related