wchar_t 的输出问题

本文解决wchar_t定义变量无法正常输出的问题,介绍了如何通过设置本地化环境来正确显示宽字符,提供了三种设置本地化的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

wchar_t 定义的变量之所以不能输出呢?我查了一下资料,就是说宽字符类型要本地化,否则输不出想要结果。
本地化有三条语句可以使用,任取其一。最后一句是全局函数,前两个是wcout的一个成员函数的两种表达方式。
std::wcout.imbue(std::locale("chs"));
std::wcout.imbue(std::locale(""));
setlocale(LC_ALL,"Chinese-simplified");
举例:
#include<iostream>
#include<string>
using namespace std;
int main(){
 wcout.imbue(std::locale("chs"));
 wstring a=L"你好 世界";
 wcout<<a;
 return 0;
}

转载于:https://www.cnblogs.com/blue1244/archive/2012/06/17/2552709.html

如下报错,如何解决 In file included from src/SM2.cc:1: In file included from src/SM2.h:3: In file included from incs/gmp.h:34: In file included from /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/iosfwd:99: In file included from /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/__mbstate_t.h:29: /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:141:77: error: use of undeclared identifier 'wcschr' wchar_t* __libcpp_wcschr(const wchar_t* __s, wchar_t __c) {return (wchar_t*)wcschr(__s, __c);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:148:87: error: use of undeclared identifier 'wcspbrk' wchar_t* __libcpp_wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcspbrk(__s1, __s2);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:155:78: error: use of undeclared identifier 'wcsrchr'; did you mean 'wcschr'? wchar_t* __libcpp_wcsrchr(const wchar_t* __s, wchar_t __c) {return (wchar_t*)wcsrchr(__s, __c);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:143:16: note: 'wcschr' declared here const wchar_t* wcschr(const wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:162:86: error: use of undeclared identifier 'wcsstr'; did you mean 'wcschr'? wchar_t* __libcpp_wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcsstr(__s1, __s2);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:145:16: note: 'wcschr' declared here wchar_t* wcschr( wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:162:86: error: no matching function for call to 'wcschr' wchar_t* __libcpp_wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcsstr(__s1, __s2);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:145:16: note: candidate disabled: <no message provided> wchar_t* wcschr( wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:162:93: error: cannot initialize a parameter of type 'wchar_t *' with an lvalue of type 'const wchar_t *' wchar_t* __libcpp_wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcsstr(__s1, __s2);} ^~~~ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:145:38: note: passing argument to parameter '__s' here wchar_t* wcschr( wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);}
最新发布
06-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值