【CString与string转换】不存在从 "LPWSTR" 转换到 "std::basic_string<char, std::char_traits<char>, std::allocator(转)

原文转自 http://blog.csdn.net/qq_23536063/article/details/52291332

 

【问题描述】

CString cstr;
sring str(cstr.GetBuffer());

编译上面代码,会出现标题中的错误。

【问题原因】因为项目编码方式为Unicode, CString中是WCHAR,string里是char,类型不匹配;CString实际是CStringT, 也就是模板类, 它在UNICODE环境下, 实际是CStringW, 而在多字符集下是CStringA,而std::string就是多字符集的

【解决方法】

CString cstr;
USES_CONVERSION;
string str(W2A(cstr));

 

posted @ 2017-12-01 15:11  ~小小鸟~  阅读(1839)  评论(0编辑  收藏  举报