MFC中CString与string的转换

MFC中CString与string的转换



Unicode下

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

//方法一 
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());

非Unicode多字节下

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

你可能感兴趣的:(工具)