您的位置:首页 > 编程语言 > C语言/C++

C语言Unicode小记

2014-01-06 16:41 120 查看
#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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: