[MFC][基本函数]StringCchPrintf()使用相关

来源:互联网 发布:知乎怎么了 编辑:程序博客网 时间:2024/04/29 10:26

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.

Copy
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>后依然无法使用,未完全解决
原创粉丝点击