第一种方法:
TCHAR pszDest[30];
size_t cchDest = 30;
LPCTSTR pszFormat = TEXT("%s%d+%s=%d.");
const TCHAR *pszTxt = TEXT("Theansweris");
string sdf = "2";
TCHAR wc[MAX_PATH];
#ifdef UNICODE
_stprintf_s(wc, MAX_PATH, _T("%S"), sdf.c_str());//%S宽字符
#else
_stprintf_s(wc, MAX_PATH, _T("%s"), sdf.c_str());//%s单字符
#endif
const TCHAR *d = wc;
HRESULT hr = StringCchPrintf(pszDest, cchDest, pszFormat, pszTxt, 1,d , 3);
第二种方法:
#include "tchar.h"
char * data = new char[str.size()+ 1];
copy(str.begin(), str.end(), data);
USES_CONVERSION;
TCHAR* tchar_temp = A2T(data);