Parameters
pszDest
[out] Pointer to a buffer that receives the formatted, null-terminated string created from pszFormat and its arguments.
cchDest
[in] Size of the destination buffer, in characters.
This value must be sufficiently large to accommodate the final formatted string plus 1 to account for the terminating null character.
The maximum number of characters allowed is STRSAFE_MAX_CCH.
大出的那一位就是放结尾0的。字符串长度计算的时候不包括结尾0。事实上拷贝的时候不需要拷贝结尾0,但是缓冲区必须多设置一个字符,并且要置为0。
Examples
The following example shows a simple use of StringCchPrintf, using four arguments.
TCHAR pszDest[30];
size_t cchDest = 30;
LPCTSTR pszFormat = TEXT("%s %d + %d = %d.");
TCHAR* pszTxt = TEXT("The answer is");
HRESULT hr = StringCchPrintf(pszDest, cchDest, pszFormat, pszTxt, 1, 2, 3);
// The resultant string at pszDest is "The answer is 1 + 2 = 3."
本文介绍了MFC中的StringCchPrintf函数,详细说明了该函数的参数含义,特别是关于缓冲区大小和null字符的重要性。示例代码展示了如何使用该函数格式化字符串。
497

被折叠的 条评论
为什么被折叠?



