Skip to content

I/O Format Specifiers for Writing Characters

A character argument has a format specifier of the following form:

%[flags] [width] [.precision] c

ModifierInterpretation
Default FunctionalityThe argument is interpreted as a single-byte character. The character is sent to the device without change.
flags -, 0Controls justification and padding of the output, as follows:
- - left aligns the result with the given field width.
0 - pads with zeros until the width is reached. If 0 and - appear together, the 0 is ignored.
widthMinimum field width of the output string. An asterisk (*) may be present in lieu of an integer width modifier, in which case an extra int argument supplies the value.
precisionMaximum number of characters to send. An asterisk (*) may be present in lieu of an integer precision modifier, in which case an extra int argument supplies the value.
HRESULT hr = S_OK;
char ch = 'A';
hr = io.Printf(_T("%c"), ch); // Sends "A"
// Field width specifies minimum width, right justify and pad to the left
hr = io.Printf(_T("%5c"), ch); // Sends " A"
// Left justify and pad to the right, field width specified with a variable
int nWidth = 5;
hr = io.Printf(_T("%-*c"), nWidth, ch); // Sends "A "