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."
添加#include <strsafe.h>后依然无法使用,未完全解决