发新帖

[C/VC/C++] string转为TCHAR

零下一度 2019-8-12 952

第一种方法:

        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);



最新回复 (0)
返回
零下一度
主题数
928
帖子数
0
注册排名
1