This tutorial introduces ANSI/ISO C++'s stream formatting capabilties, including stream manipulators, justification, padding, integer formats, floating-point number formats, uppercase/lowercase control, formatting booleans as strings, and setting and restoring stream format states. This tutorial is intented for students and developers who are familiar with basic C++ input and output techniques using cin and cout. The techniques shown here can also be applied to file-based streams or other streams that extend the standard C++ stream class hierarchy.
Download the code examples for this tutorial.
[Note: This tutorial is an excerpt (Section 15.7) of Chapter 15, Stream Input/Output, from our textbook C++ How to Program, 5/e. These tutorials may refer to other chapters or sections of the book that are not included here. Permission Information: Deitel, Harvey M. and Paul J., C++ HOW TO PROGRAM, ©2005, pp.787-797. Electronically reproduced by permission of Pearson Education, Inc., Upper Saddle River, New Jersey.]
15.7 Stream Format States and Stream Manipulators (Continued)
15.7.6 Uppercase/Lowercase Control (uppercase)
Stream manipulator uppercase outputs an uppercase X or E with hexadecimal-integer values or with scientific-notation floating-point values, respectively (Fig. 15.19). Using stream manipulator uppercase also causes all letters in a hexadecimal value to be uppercase. By default, the letters for hexadecimal values and the exponents in scientific-notation floating-point values appear in lowercase. To reset the uppercase setting, output the stream-manipulator nouppercase.
|
||
| Fig. 15.19 | Stream manipulator uppercase. |
|
Printing uppercase letters in scientific notation exponents and hexadecimal values: 4.345E+010 0X75BCD15 |
Other sections in this tutorial:
Introduction to Stream Format States and Stream Manipulators
15.7.1 Trailing Zeros and Decimal Points (showpoint)
15.7.2 Justification (left, right and internal)
15.7.3 Padding (fill, setfill)
15.7.4 Integral Stream Base (dec, oct, hex, showbase)
15.7.5 Floating-Point Numbers; Scientific and Fixed Notation (scientific, fixed)
15.7.6 Uppercase/Lowercase Control (uppercase) (You are here).
15.7.7 Specifying Boolean Format (boolalpha)
15.7.8 Setting and Resetting the Format State via Member Function flags

