vc++ CString、string、const char*的相互转换(环境 vs2010)
2021-02-07 14:19
标签:nbsp ring sprint 相互 hello temp char bsp c++ 1.CString 转 string //第一种方式 CString str = _T("Hello wrold"); USER_CONVERSION; std::string s(W2A(str)); //第二种方式 CString str = _T("Hello wrold"); std::string s = (CT2A)str; 2.string 转 CString CString str; std::string s="Hello world!"; str=s.c_str(); 3.CString 转 const char* //第一种方式(CString转char*转const char*) CString str = _T("Hello wrold"); const char* cstr; char temp[100]; ::wsprintfA(temp, "%ls",(LPCTSTR)str); cstr = temp; //第二种方式 (CString 转string转const char*) CString str = _T("Hello wrold"); USER_CONVERSION; std::string s(W2A(str)); const char* cstr = s.c_str(); 4.const char* 转 CString const char* cstr = "Hello World!"; CString str(cstr); vc++ CString、string、const char*的相互转换(环境 vs2010) 标签:nbsp ring sprint 相互 hello temp char bsp c++ 原文地址:https://www.cnblogs.com/xmr183729/p/12775932.html
上一篇:Java专题十八:注解
下一篇:Java专题十六:定时任务
文章标题:vc++ CString、string、const char*的相互转换(环境 vs2010)
文章链接:http://soscw.com/index.php/essay/52225.html