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

Info iconThis 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

This note was uploaded on 02/18/2012 for the course CSCE 121 taught by Professor Walter daugherity during the Fall '09 term at Texas A&M.

Ask a homework question - tutors are online