Chapter 11

# Chapter 11

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Chapter 11 Chapter Customizing I/O Bjarne Stroustrup www.stroustup.com/Programming Overview Overview Input and output Numeric output File modes Integer Floating point Binary I/O Positioning String streams Line-oriented input Character input Character classification Stroustrup/Programming 2 Kinds of I/O Kinds Individual values Streams See Chapters 12-16 Text See Chapters 10-11 Graphics and GUI See Chapter 4, 10 Type driven, formatted Line oriented Individual characters Numeric Integer Floating point User-defined types Stroustrup/Programming 3 Observation Observation As programmers we prefer regularity and simplicity But, our job is to meet people’s expectations People are very fussy/particular/picky about the way People their output looks their They often have good reasons to be Convention/tradition rules What does 123,456 mean? What does (123) mean? The world (of output formats) is weirder than you could The possibly imagine possibly Stroustrup/Programming 4 Output formats Output Integer values 1234.57 1.2345678e+03 1234.567890 (general) (scientific) (fixed) Precision (for floating-point values) (decimal) (octal) (hexadecimal) Floating point values 1234 2322 4d2 1234.57 1234.6 (precision 6) (precision 5) Fields |12| | 12| (default for | followed by 12 followed by |) (default 12 (12 in a field of 4 characters) Stroustrup/Programming 5 Numerical Base Output Numerical 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 << dec << 1234 << "\t(decimal)\n" << hex << 1234 << "\t(hexadecimal)\n" << oct << 1234 << "\t(octal)\n"; // The '\t' character is “tab” (short for “tabulation character”) // The // results: results: 1234 4d2 2322 2322 (decimal) (hexadecimal) (hexadecimal) (octal) Stroustrup/Programming 6 “Sticky” Manipulators Sticky” 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 << '\n'; cout << 1234 << '\n'; // the octal base is still in effect // the // results: // results: 1234 2322 4d2 2322 Stroustrup/Programming 7 Other Manipulators O...
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