Function printUniversal
(lines 33–37 of Fig. 9.2) takes no arguments and outputs the time in universal-time format, consisting of three colon-separated pairs of digits. If the time were 1:30:07 PM, function printUniversal
would return 13:30:07
. Line 35 uses parameterized stream manipulator setfill to specify the fill character that’s displayed when an integer is output in a field wider than the number of digits in the value. The fill characters appear to the left of the digits in the number, because the number is right aligned by default—for left aligned values, the fill characters would appear to the right. In this example, if the minute
value is 2, it will be displayed as 02, because the fill character is set to zero ('0'
). If the number being output fills the specified field, the fill character will not be displayed. Once the fill character is specified with setfill
, it applies for all subsequent values that are displayed in fields wider than the value being displayed—setfill
is a “sticky” setting. This is in contrast to setw
, which applies only to the next value displayed—setw
is a “nonsticky” setting.
Error-Prevention Tip 9.2
Each sticky setting (such as a fill character or floating-point precision) should be restored to its previous setting when it’s no longer needed. Failure to do so may result in incorrectly formatted output later in a program. Chapter 13, Stream Input/Output: A Deeper Look, discusses how to reset the fill character and precision.
18.218.114.244