Condividi tramite


CStringT::Format

Writes formatted data to a CStringT in the same way that sprintf_s formats data into a C-style character array.

void __cdecl Format(
   UINT nFormatID,
   [, argument]...
);
void __cdecl Format(
   PCXSTR pszFormat,
   [, argument]...
);

Parameters

  • nFormatID
    The string resource identifier that contains the format-control string.

  • pszFormat
    A format-control string.

  • argument
    Optional arguments.

Remarks

This function formats and stores a series of characters and values in the CStringT. Each optional argument (if any) is converted and output according to the corresponding format specification in pszFormat or from the string resource identified by nFormatID.

The call will fail if the string object itself is offered as a parameter to Format. For example, the following code will cause unpredictable results:

CAtlString str = _T("Some Data");
str.Format(_T("%s%d"), str, 123);   
// Attention: str is also used in the parameter list.   

For more information, see Format Specification Syntax: printf and wprintf Functions.

Example

// typedef CStringT<TCHAR, StrTraitATL<TCHAR, ChTraitsCRT<TCHAR>>> CAtlString;
CAtlString str;

str.Format(_T("Floating point: %.2f\n"), 12345.12345);
_tprintf_s(_T("%s"), (LPCTSTR) str);

str.Format(_T("Left-justified integer: %.6d\n"), 35);
_tprintf_s(_T("%s"), (LPCTSTR) str);

Requirements

Header: cstringt.h

See Also

Reference

CStringT Class

sprintf_s, _sprintf_s_l, swprintf_s, _swprintf_s_l