字符串各种纠结

来源:互联网 发布:js 双向绑定 编辑:程序博客网 时间:2024/05/23 20:59

http://zhidao.baidu.com/question/292945651.html

int main(int argc, char* argv[]){TCHAR a[]=_T("ghfh");TCHAR b[1024];wsprintf(b,_T("a=%s\n"),a); _tprintf(_T("%s\n"),b);return 0;}

如果你调用LPCTSTR类型的,都要用_T宏,如果是LPCWSTR的用L。程序里面不要混用char, wchar_t和TCHAR的类型,否则写得不适当很容易出现编译错误。

 

BSTR 转换成TCHAR *的方法

http://prokuso.com/2006/07/bstr.html

后来找到的真正简单的方法是利用_bstr_t建一个中间变量,然后直接给char*赋值。

BSTR strName;
 _bstr_t bstrTName = strName;
 TCHAR* szFilePath = bstrTName;
 
CString 转换成TCHAR *的方法:

http://www.cnblogs.com/gakusei/archive/2009/05/21/1485950.html

CString theString( "This is a test" );
LPTSTR lpsz = new TCHAR[theString.GetLength()+1];
_tcscpy(lpsz, theString);


 
原创粉丝点击