CString 转换成string vs2010

来源:互联网 发布:数据分析挖掘主观题 编辑:程序博客网 时间:2024/05/16 12:49
CString 转换成string
我试了很多的方法,都不行,我用的vs2010,大家给提供个正确的方法。没验证过的可就别参和了。

------解决方案--------------------
unicode:
CString sz1 = L"abc";
std::string sz2 = CT2A(sz1.GetBuffer()); //转化为非unicode.

非unicode:
CString sz1 = "abc";
std::string sz2 = sz1.GetBuffer(); 

------解决方案--------------------
楼上正解,再提供几个UNICODE下的方法
C/C++ code
//方法一CString theCStr;std::string STDStr( CW2A( theCStr.GetString() ) );//方法二CString m_Name;CT2CA pszName(m_Name);std::string m_NameStd(pszName);//方法三CString str = L"Test";std::wstring ws(str);std::string s; s.assign(ws.begin(), ws.end());
   http://www.myexception.cn/vc-mfc/153485.html
原创粉丝点击