CString 转换成string vs2010

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值