// 从 unicode 字符串转化为 ansi字符串
string s = (char *) _bstr_t ( ws2.c_str() );
// 从 ansi字符串转化为 unicode 字符串
ws1 = ( wchar_t *) ( _bstr_t ( s.c_str( ) ));
setlocale(LC_ALL, "chs");
wprintf( L"原wstring串=%s\n",ws2.c_str());
printf( "转换为string串=%s\n", s.c_str());
wprintf( L"转换为wstring串=%s\n",ws1.c_str());
::CoUninitialize();
getchar();
return 0;
}
本文介绍了如何在C++中实现Unicode字符串与ANSI字符串之间的相互转换。通过使用_bstr_t,可以方便地进行编码转换,并展示了具体的代码实现。
656

被折叠的 条评论
为什么被折叠?



