Содержание
- 2. Overview Input and output Numeric output Integer Floating point File modes Binary I/O Positioning String streams
- 3. Kinds of I/O Individual values See Chapters 4, 10 Streams See Chapters 10-11 Graphics and GUI
- 4. Observation As programmers we prefer regularity and simplicity But, our job is to meet people’s expectations
- 5. Output formats Integer values 1234 (decimal) 2322 (octal) 4d2 (hexadecimal) Floating point values 1234.57 (general) 1.2345678e+03
- 6. Numerical Base Output You can change “base” Base 10 == decimal; digits: 0 1 2 3
- 7. “Sticky” Manipulators You can change “base” Base 10 == decimal; digits: 0 1 2 3 4
- 8. Other Manipulators You can change “base” Base 10 == decimal; digits: 0 1 2 3 4
- 9. Floating-point Manipulators You can change floating-point output format defaultfloat – iostream chooses best format using n
- 10. Precision Manipulator Precision (the default is 6) defaultfloat – precision is the number of digits scientific
- 11. Output field width A width is the number of characters to be used for the next
- 12. Observation This kind of detail is what you need textbooks, manuals, references, online support, etc. for
- 13. A file At the fundamental level, a file is a sequence of bytes numbered from 0
- 14. File open modes By default, an ifstream opens its file for reading By default, an ofstream
- 15. Text vs. binary files In binary files, we use sizes to delimit values In text files,
- 16. Text vs. binary Use text when you can You can read it (without a fancy program)
- 17. Binary files int main() // use binary input and output { cout string iname; cin >>
- 18. Binary files vector v; // read from binary file: for (int i; ifs.read(as_bytes(i),sizeof(int)); ) // note:
- 19. Positioning in a filestream fstream fs {name}; // open for input and output // … fs.seekg(5);
- 20. Positioning Whenever you can Use simple streaming Streams/streaming is a very powerful metaphor Write most of
- 21. String streams A stringstream reads/writes from/to a string rather than a file or a keyboard/screen double
- 22. String streams See textbook for ostringstream String streams are very useful for formatting into a fixed-sized
- 23. Type vs. line Read a string string name; cin >> name; // input: Dennis Ritchie cout
- 24. Characters You can also read individual characters for (char ch; cin>>ch; ) { // read into
- 25. Character classification functions If you use character input, you often need one or more of these
- 26. Line-oriented input Prefer >> to getline() i.e. avoid line-oriented input when you can People often use
- 27. C++14 Binary literals 0b1010100100000011 Digit separators 0b1010'1001'0000'0011 Can also be used for for decimal, octal, and
- 29. Скачать презентацию