![]() | I/O Format Specifiers for Writing Integers |
An integer argument has a format specifier of the following form:
%[flags] [488.2 type] [width] [.precision] [delimiter [array size] ] [$S] [b | h | l | I] [d | o | x]
Modifier | Interpretation |
---|---|
Default Functionality | The argument is formatted as an integer in NR1 format (an integer without a decimal point). |
flags +, -, 0 | Controls justification and padding of the output, as follows:
|
488.2 type | The number is formatted in one of six standard IEEE 488.2 numeric formats. The supported formats are:
|
width | Minimum field width of the output number. An asterisk (*) may be present in lieu of an integer width modifier, in which case an extra int argument supplies the value. |
precision | Minimum number of digits to send. An asterisk (*) may be present in lieu of an integer precision modifier, in which case an extra int argument supplies the value. |
delimiter [array size] | The argument is interpreted as an array of integers (or long or short integers, as specified by the length). If the $S modifier is present, the argument is interpreted as a SAFEARRAY of integers. array size specifies the number of array elements to send. An asterisk (*) may be present in lieu of an integer array size modifier, in which case an extra int argument supplies the value. |
$S | The argument is interpreted as a SAFEARRAY of integers. |
length modifier | If no length modifier is specified, then the argument is assumed to be a long integer (32-bits).
|
type |
|
HRESULT hr = S_OK; int nCount = 1234; // Left justify hr = io.Printf(_T("%-8d"), nCount); // Sends "1234 " // Right justify hr = io.Printf(_T("%8d"), nCount); // Sends " 1234" // Right justify, pad with zeroes hr = io.Printf(_T("%08d"), nCount); // Sends "00001234" // Supply field width using a variable int nWidth = 5; hr = io.Printf(_T("%0*d"), nWidth, lCount); // Sends "00123";
HRESULT hr = S_OK; int nCount = 1234; hr = io.Printf(_T("%d"), nCount); // Sends "1234" long lCount = 1234; hr = io.Printf(_T("%ld"), lCount); // Sends "1234" short sCount = 1234; hr = io.Printf(_T("%hd"), sCount); // Sends "1234"
HRESULT hr = S_OK; int rgData[] = { 1, 2, 3, 4, 5 }; // Comma-separated list of 3 elements hr = io.Printf(_T("%,3d"), rgData); // Sends "1,2,3" // Semi-colon separated, count supplied as a variable int nCount = 4; hr = io.Printf(_T("%(;)*d"), nCount, rgData); // Sends "1;2;3;4" // Field width specified applies to each element hr = io.Printf(_T("%4,3d"), rgData); // Sends " 1, 2, 3" CComSafeArray<int> saData; saData.Add(1); saData.Add(3); saData.Add(3); // Comma-separated list. Argument is a SAFEARRAY. // No field width supplied, so count is determined from the SAFEARRAY itself. hr = io.Printf(_T("%,$Sd"), saData.m_psa); // Sends "1,2,3"
HRESULT hr = S_OK; // Format value as an IEEE-defined hex number int nMask = 1234; hr = io.Printf(_T("%@Hd"), nMask); // Sends "#H7B" // Format value as an IEEE-defined binary number hr = io.Printf(_T("%@Hd"), nMask); // Sends "#B1111011" int rgData[] = { 1, 2, 3, 4, 5 }; // Field width of 5 includes the "#B", pad with zeros hr = io.Printf(_T("%@B05,5d"), rgData); // Sends "#B001,#B010,#B011,#B100,#B101"