56 setw4 123456 setw8 123456

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: s to be used for the next width output operation output Beware: width applies to next output only (it doesn’t “stick” like Beware: precision, base, and floating-point format) precision, Beware: output is never truncated to fit into field (better a bad format than a bad value) // example: // example: cout << 123456 <<'|'<< setw(4) << 123456 << '|' << setw(8) << 123456 << '|' << 123456 << "|\n"; cout << 1234.56 <<'|'<< setw(4) << 1234.56 << '|' << setw(8) << 1234.56 << '|' << 1234.56 << "|\n"; cout << "asdfgh" <<'|'<< setw(4) << "asdfgh" << '|' << setw(8) << "asdfgh" << '|' << "asdfgh" << "|\n"; // results: // results: 123456|123456| 123456|123456| 1234.56|1234.56| 1234.56|1234.56| asdfgh|asdfgh| asdfgh|asdfgh| Stroustrup/Programming 11 Observation Observation This kind of detail is what you need textbooks, This manuals, references, online support, etc. for manuals, You always forget some of the details when you need them You always Stroustrup/Programming 12 A file file 0: 1: 2: At the fundamental level, a file is a sequence of At bytes numbered from 0 upwards bytes Other notions can be supplied by programs that Other interpret a “file format” interpret For example, the 6 bytes "123.45" might be interpreted For as the floating-point number 123.45 Stroustrup/Programming 13 13 File open modes File By default, an ifstream opens its file for reading By ifstream By default, an ofstream opens its file for writing. By ofstream Alternatives: ios_base::app ios_base::ate ios_base::binary ios_base::binary ios_base::in ios_base::out ios_base::trunc // append (i.e., add to the end of the file) append // “at end” (open and seek to end) “at // binary mode – beware of system specific behavior binary // for reading for // for writing for // truncate file to 0-length truncate A file mode is optionally spe...
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