tailieunhanh - Lecture Programming principles and practice using C++: Chapter 11 - Bjarne Stroustrup
In this chapter, we concentrate on how to adapt the general iostreams framework presented in Chapter 10 to specific needs and tastes. A number of ways are presented in which we can tailor input and output to our needs. In this chapter, you learned to: Input and output, numeric output, file modes, string streams, line-oriented input. | Chapter 11 Customizing I/O Bjarne Stroustrup Overview Input and output Numeric output Integer Floating point File modes Binary I/O Positioning String streams Line-oriented input Character input Character classification Stroustrup/Programming/2015 Kinds of I/O Individual values See Chapters 4, 10 Streams See Chapters 10-11 Graphics and GUI See Chapters 12-16 Text Type driven, formatted Line oriented Individual characters Numeric Integer Floating point User-defined types Stroustrup/Programming/2015 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 their output looks They often have good reasons to be Convention/tradition rules What does 110 mean? What does 123,456 mean? What does (123) mean? The world (of output formats) is weirder than you could possibly imagine Stroustrup/Programming/2015 Output formats Integer . | Chapter 11 Customizing I/O Bjarne Stroustrup Overview Input and output Numeric output Integer Floating point File modes Binary I/O Positioning String streams Line-oriented input Character input Character classification Stroustrup/Programming/2015 Kinds of I/O Individual values See Chapters 4, 10 Streams See Chapters 10-11 Graphics and GUI See Chapters 12-16 Text Type driven, formatted Line oriented Individual characters Numeric Integer Floating point User-defined types Stroustrup/Programming/2015 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 their output looks They often have good reasons to be Convention/tradition rules What does 110 mean? What does 123,456 mean? What does (123) mean? The world (of output formats) is weirder than you could possibly imagine Stroustrup/Programming/2015 Output formats Integer values 1234 (decimal) 2322 (octal) 4d2 (hexadecimal) Floating point values (general) (scientific) (fixed) Precision (for floating-point values) (precision 6) (precision 5) Fields |12| (default for | followed by 12 followed by |) | 12| (12 in a field of 4 characters) Stroustrup/Programming/2015 Numerical Base Output 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: cout Stroustrup/Programming/2015 “Sticky” Manipulators 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
đang nạp các trang xem trước