{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

0 1 2 3 4 5 6 7 8 9 base 8 octal digits 0 1 2 3 4 5 6

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ther You can change “base” Base 10 == decimal; digits: 0 1 2 3 4 5 6 7 8 9 Base 8 == octal; digits: 0 1 2 3 4 5 6 7 Base 16 == hexadecimal; digits: 0 1 2 3 4 5 6 7 8 9 a b c d e f // simple test: // simple cout << 1234 << '\t' << hex << 1234 << '\t' << oct << 1234 << endl; cout << showbase << dec; // show bases // show cout << 1234 << '\t' << hex << 1234 << '\t' << oct << 1234 << '\n'; // results: // results: 1234 4d2 2322 1234 0x4d2 02322 Stroustrup/Programming // '\n' // '\n' 8 Floating-point Manipulators Floating-point You can change floating-point output format general – iostream chooses best format using n digits (this is the default) general iostream scientific – one digit before the decimal point plus exponent; n digits after . fixed – no exponent; n digits after the decimal point // simple test: // simple cout << 1234.56789 << "\t\t(general)\n" // \t\t to line up columns // \t\t << fixed << 1234.56789 << "\t(fixed)\n" << << scientific << 1234.56789 << "\t(scientific)\n"; << // results: // results: 1234.57 1234.567890 1234.567890 1.234568e+003 (general) (general) (fixed) (scientific) Stroustrup/Programming 9 Precision Manipulator Precision Precision (the default is 6) general – precision is the number of digits general Note: the general manipulator is not standard, just in std_lib_facilities.h Note: manipulator scientific – precision is the number of digits after the . (dot) fixed – precision is the number of digits after the . (dot) // example: // example: cout << 1234.56789 << '\t' << fixed << 1234.56789 << '\t' << scientific << 1234.56789 << '\n'; cout << general << setprecision(5) << 1234.56789 << '\t' << fixed << 1234.56789 << '\t' << scientific << 1234.56789 << '\n'; cout << general << setprecision(8) << 1234.56789 << '\t' << fixed << 1234.56789 << '\t' << scientific << 1234.56789 << '\n'; // results (note the rounding): // results 1234.57 1234.567890 1.234568e+003 1234.6 1234.56789 1.23457e+003 1234.5679 1234.56789000 1.23456789e+003 Stroustrup/Programming 10 Output field width Output A width is the number of character...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern