This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: 451–F02 7.2 – 1 / 8 )RUPDWWLQJ ZLWK 0DQLSXODWRUV EULHI LQWURGXFWLRQ Reference: Lippman and Lajoie, sec 20.9 T There are two ways to control the formatting of values written to an output stream: i) By invoking methods of the stream directly, ii) By using manipulators (which in turn invoke methods of the stream). B Usually, it is more convenient to use manipulators. B We have already seen several manipulators: endl , setw() , hex , dec . cout << setw(5) << i << endl; B Manipulators are most often used with output streams, but some apply to input streams as well. • We will consider only output streams. 451–F02 7.2 – 2 / 8 T Here are some of the more useful manipulators. Manipulator Meaning endl Write a newline character, and then flush output buffer. setw( w ) Display the next value written in field of width w. ( w is a minimum width; a wider field will be used, if needed.) Default: 0 (reset to 0 after each value written). Note 0 says: use the smallest width that will hold the value — no padding. setfill( c ) Use character c as the padding character. (Padding occurs only if setw() has been used to specify a field width larger than needed.) Default : blank. setprecision( p ) For floating point numbers, display p digits (fixed format) or p digits after the decimal point (scientific format)....
View Full Document
This note was uploaded on 06/30/2011 for the course PHYSICS 780 taught by Professor Furnstahl during the Winter '11 term at Ohio State.
- Winter '11