std::string在UNICODE下遇到的问题
以前我好像问过一次,那次采用的变通的方法,是把std::string类型改为CString类。但现在还需要std::string类,所以再次请教。我程序中有这样的代码:
catch ( _com_error &e )
{
std::string errmsg( e.ErrorMessage() );
lstrcat(szMsg, (LPCTSTR)errmsg.c_str());
bRes = FALSE;
}
在UNICODE下编译时,std::string errmsg( e.ErrorMessage() );不能通过,原因是在UNICODE版本下,e.ErrorMessage()的类型和std::string不能匹配,具体编译输出的信息为:
error C2664: '__thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(const class st
d::allocator<char> &)' : cannot convert parameter 1 from 'const unsigned short *' to 'const class std::allocator<char> &'
Reason: cannot convert from 'const unsigned short *' to 'const class std::allocator<char>'
No constructor could take the source type, or constructor overload resolution was ambiguous
我现在必须编译出一个UNICODE版本,而且保证不改变std::string类型,怎么才能使程序通过编译呢,大家帮忙啊!