- 论坛徽章:
- 24
|
回复 1楼 zhujiang73 的帖子
- #include <locale>
- #include <stdlib.h>
- #include <stdio.h>
- #include <clocale>
- #include <iostream>
- #include <string>
- #include <sstream>
- char narrow[100];
- wchar_t word[100];
- const char *from = narrow;
- const char *nstart = narrow;
- wchar_t *to = 0;
- wchar_t *wstart = word;
- mbstate_t cs;
- std::wstring my_wstr;
- int main( )
- {
- std::locale::global(std::locale(""));
- snprintf(narrow, 99, "%s", "12 测试 abc 你好");
-
- std::use_facet< std::codecvt<wchar_t, char, mbstate_t> >(std::locale("")).in(cs, nstart, nstart+strlen(narrow), from, wstart,wstart+100, to );
- my_wstr = word;
- std::wcout << L"word = " << word << std::endl;
- std::wcout << L"my_wstr = " << my_wstr << std::endl;
- std::wcout << L"wcslen word = " << wcslen(word) << std::endl;
-
- return 0;
- }
复制代码
成了,在我的 debian
上面,不过上面的代码是我参考了一些资料后照猫画虎而成。还是没全懂,继续研究。![](static/image/smiley/default/icon_smile.gif)
参考资料:
http://book.77169.com/data/web5603/20050228/20050228__3334439.html
http://www.tacc.utexas.edu/services/userguides/pgi/pgC++_lib/stdlibug/sta_9169.htm
http://www.cantrip.org/locale.html |
|