|
下面的代码,我想把输入的字符串转化为宽字符型。
- #include<string>
- #include<iostream>
- using namespace std;
- int
- main()
- {
- wstring str;
- wcin.imbue(locale("zh_CN.GBK"));
- wcin >> str;
- wcout << L"size =" << str.size() << endl;
- wcout << L"str =" << str << endl;
- return 0;
- }
复制代码
使用g++ -o test test.cpp -D_LIBCPP_WCHAT_T 编译
在windows中使用dev-cpp编译通不过(wchar.t中的vwscanf没有声明),在linux中编译通过,但是运行却有问题:不能输入中文。
>./test
中文测试
>size = 0
str =
>./test
中文测试123
>size = 0
str =
>./test
123中文测试
>size = 3
str = 123 |
|