- UID
- 11157
- UCC
-
- 声望
-
- 好评
-
- 贡献
-
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2008-6-20 15:13:49
|
显示全部楼层
我找到一些 ws2s 的代碼如下:- #include <string>
- std::string ws2s(const std::wstring& ws)
- {
- std::string curLocale = setlocale(LC_ALL, NULL); // curLocale = "C";
- setlocale(LC_ALL, "chs");
- const wchar_t* _Source = ws.c_str();
- size_t _Dsize = 2 * ws.size() + 1;
- char *_Dest = new char[_Dsize];
- memset(_Dest,0,_Dsize);
- wcstombs(_Dest,_Source,_Dsize);
- std::string result = _Dest;
- delete []_Dest;
- setlocale(LC_ALL, curLocale.c_str());
- return result;
- }
- std::wstring s2ws(const std::string& s)
- {
- setlocale(LC_ALL, "chs");
- const char* _Source = s.c_str();
- size_t _Dsize = s.size() + 1;
- wchar_t *_Dest = new wchar_t[_Dsize];
- wmemset(_Dest, 0, _Dsize);
- mbstowcs(_Dest,_Source,_Dsize);
- std::wstring result = _Dest;
- delete []_Dest;
- setlocale(LC_ALL, "C");
- return result;
- }
复制代码 是不是這個?如果是,要加在哪邊? |
|