ios::showpoint. TABLE17.1 shows some of the flags you can use. When using these
flags, you need to include iostreamin your listing. In addition, for those flags that
require parameters, you need to include iomanip.
TABLE17.1 Some of the iostreamSet Flags
Flag Purpose
showpoint Displays a decimal point and trailing zeros as required by precision
showpos Turns on the plus sign (+) before positive numbers
left Aligns output to the left
right Aligns output to the right
internal Aligns the sign for a number to the left and aligns the value to the right
showpoint Adds trailing zeros as required by the precision
showpos Displays a plus sign (+) if the number is positive
scientific Shows floating-point values in scientific notation
fixed Shows floating-point numbers in decimal notation
showbase Adds “0x” in front of hexadecimal numbers to indicate that it is a
hexadecimal value
Uppercase Shows hexadecimal and scientific numbers in uppercase
dec Sets the base of the numbers for display to decimal
oct Sets the base of the numbers for display to octal—base 8
hex Sets the base of the numbers for display to hexadecimal—base 16
The flags in Table 17.1 can also be concatenated into the insertion operator. Listing
17.14 illustrates these settings. As a bonus, Listing 17.14 also introduces the setwmanip-
ulator, which sets the width but can also be concatenated with the insertion operator.
LISTING17.14 Using setf
0: // Listing 17.14 - Using setf
1: #include <iostream>
2: #include <iomanip>
3: using namespace std;
4:
5: int main()
6: {
7: const int number = 185;
8: cout << “The number is “ << number << endl;
9:
10: cout << “The number is “ << hex << number << endl;
618 Day 17