Version 9 (modified by 20 months ago) ( diff ) | ,
---|
StrFmt
Format a string with a format specifier and a variable number of parameters.
string StrFmt(const char* pszFmt, ...); void StrFmt(string& str, const char* pszFmt, ...);
Parameters
- pszFmt - character array of formatting information
- ... - variable number of parameters to fill in formatting specifiers
Return Value
- Returns the formatted string
Remarks
This is basically a wrapper around sprintf to provide the flexibility of formatting with some safety measures built in. If string parameters are used the ".c_str()" method will be needed to convert this to C style strings. Refer to http://www.cplusplus.com/reference/clibrary/cstdio/printf/ for formatting specifiers.
Example
int nVal = 123; string strID = "ABC"; string strMsg; strMsg = StrFmt("Number: %d ID: %s", nVal, strID.c_str());
The version of StrFmt shown below that takes a reference to the string as a parameter is more efficient. This is because it doesn't have to create the string, and pass it as a return value to tbe recreated.
int nVal = 123; string strID = "ABC"; string strMsg; StrFmt(strMsg, "Number: %d ID: %s", nVal, strID.c_str());
See Also
Note:
See TracWiki
for help on using the wiki.