C语言Unicode小记

#include <stdio.h>
#include <locale.h>
#include <stdlib.h>
#include <wchar.h>

const int SIZE = 100;

int main(void)
{
	wchar_t wstr[SIZE];
	//wchar_t wstr[] = {0x5b89, 0x5353, 0};

	/*本地化,设置语言运行环境*/
	setlocale(LC_ALL, "Chinese-simplified"); // locale.h

    //wscanf(L"%s", wstr);
    // 如果编译时遇到Illegal byte sequence错误,
    // 拿CodeBlocks这个IDE来说
    // 请在Settings-Compiler-Global compiler settings-Compiler settings-Other options中
    // 加上-finput-charset=GBK这个编译选项
	wcscpy(wstr, L"HELLO世界hello"); // stdlib.h

	int i;
	for (i = 0; wstr[i]; ++i)
		printf("%#06X\n", wstr[i]);

    wprintf(L"%ls\n", wstr);
    //fputws(wstr, stdout);
	return 0;
}

输出结果:

0X0048
0X0045
0X004C
0X004C
0X004F
0X4E16
0X754C
0X0068
0X0065
0X006C
0X006C
0X006F
HELLO世界hello

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值