如何初始化和打印unicode字符? [英] how to initial and print the unicode character?

查看:109
本文介绍了如何初始化和打印unicode字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想尝试ANSI C99的unicode功能。所以我写了一个测试程序。

函数很简单,但我无法用windows cp sp2下的dev c ++ 4.9.9.2

编译它,因为编译器总是认为

初始化wchar_t字符串是非法的。这是我的功能:

#include< stdio.h>

#include< stdlib.h>

#include< wchar .h>

#include< wctype.h>

#include< string.h>


int main( int argc,char * argv [])

{

wchar_t * cur_buff = L" X";

wprintf(cur_buff);

返回0;

}


函数中,wchar_t * cur_buff的初始化为LX,如果X

是一个ascii字符,然后所有东西都运行良好。但是如果X是一个非中文字符的非ascii字符,编译器会警告这是一个非法的字节序列。源文件保存为ascci

代码,字符集为gb2312。我想知道为什么会这样?

i want to try ANSI C99''s unicode fuctions. so i write a test program.
the function is simple, but i cannot compile it with dev c++ 4.9.9.2
under windows xp sp2, since the compiler always think that the
initialization of the wchar_t string is illegal. here is my function:
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <wctype.h>
#include <string.h>

int main(int argc, char *argv[])
{
wchar_t *cur_buff=L"X";
wprintf(cur_buff);
return 0;
}

in the function, the initialization of wchar_t *cur_buff is L"X", if X
is an ascii character, then all things function well. But if X is
non-ascii charater such as a Chinese character, compiler would alert
that this is a illegal byte sequence. The source file is saved as ascci
code, and the character set is gb2312. i wonder why this happens?

推荐答案

2006-07-04,wizardyhnr< wi ******** @ gmail.comwrote:
On 2006-07-04, wizardyhnr <wi********@gmail.comwrote:

i想尝试ANSI C99的unicode功能。所以我写了一个测试程序。

函数很简单,但我无法用windows cp sp2下的dev c ++ 4.9.9.2

编译它,因为编译器总是认为

初始化wchar_t字符串是非法的。这是我的功能:
i want to try ANSI C99''s unicode fuctions. so i write a test program.
the function is simple, but i cannot compile it with dev c++ 4.9.9.2
under windows xp sp2, since the compiler always think that the
initialization of the wchar_t string is illegal. here is my function:



如果不看你的实际问题,这里有一些提示:

1)这是公平的不太可能你真的有一个C99编译器。

2)用C ++这个词来表达的东西是不太可能的。在其中

甚至是C编译器,更不用说是C99编译器了。


除此之外,我们不关心你有什么操作系统或平台。我们在这里讨论了

标准C,这个平台是独立的。


-

Andrew Poelstra< http: //www.wpsoftware.net/blog>

要给我发电子邮件,请使用apoelstra。在上面的地址。

你们人讨厌数学。 - James Harris

Without looking at your actual problem, here''s a few tips:
1) It''s fairly unlikely that you actually have a C99 compiler.
2) It''s very unlikely that something with the word "C++" in it
is even a C compiler, let alone a C99 compiler.

Other than that, we don''t care what OS or platform you have. We discuss
standard C here, and that''s platform independant.

--
Andrew Poelstra <http://www.wpsoftware.net/blog>
To email me, use "apoelstra" at the above address.
"You people hate mathematics." -- James Harris


* wizardyhnr:
* wizardyhnr:

我想尝试ANSI C99的unicode功能。所以我写了一个测试程序。

函数很简单,但我无法用windows cp sp2下的dev c ++ 4.9.9.2

编译它,因为编译器总是认为

初始化wchar_t字符串是非法的。这是我的功能:

#include< stdio.h>

#include< stdlib.h>

#include< wchar .h>

#include< wctype.h>

#include< string.h>


int main( int argc,char * argv [])

{

wchar_t * cur_buff = L" X";

wprintf(cur_buff);

返回0;

}


函数中,wchar_t * cur_buff的初始化为LX,如果X

是一个ascii字符,然后所有东西都运行良好。但是如果X是一个非中文字符的非ascii字符,编译器会警告这是一个非法的字节序列。源文件保存为ascci

代码,字符集为gb2312。我想知道为什么会这样?
i want to try ANSI C99''s unicode fuctions. so i write a test program.
the function is simple, but i cannot compile it with dev c++ 4.9.9.2
under windows xp sp2, since the compiler always think that the
initialization of the wchar_t string is illegal. here is my function:
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <wctype.h>
#include <string.h>

int main(int argc, char *argv[])
{
wchar_t *cur_buff=L"X";
wprintf(cur_buff);
return 0;
}

in the function, the initialization of wchar_t *cur_buff is L"X", if X
is an ascii character, then all things function well. But if X is
non-ascii charater such as a Chinese character, compiler would alert
that this is a illegal byte sequence. The source file is saved as ascci
code, and the character set is gb2312. i wonder why this happens?



不知道C,但是在C ++中你必须在那里放一个'const',

wchar_t const * curr_buff = L" X";


-

答:因为它弄乱了人们通常阅读的顺序文字。

问:为什么这么糟糕?

A:热门帖子。

问:什么是最烦人的事情在usenet和电子邮件中?

Don''t know about C, but in C++ you''d have to put a ''const'' in there,

wchar_t const* curr_buff = L"X";

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


" Alf P. Steinbach" < al *** @ start.nowrites:
"Alf P. Steinbach" <al***@start.nowrites:

* wizardyhnr:
* wizardyhnr:

> wchar_t * cur_buff = LX;
> wchar_t *cur_buff=L"X";



不知道C,但是在C ++中你必须在那里放一个'const',

wchar_t const * curr_buff = LX;


Don''t know about C, but in C++ you''d have to put a ''const'' in there,
wchar_t const* curr_buff = L"X";



不在C中。

-

它不会是新的C标准如果它没有给静态这个词带来新的含义。

- C99上的彼得斯巴赫

Not in C.
--
"It wouldn''t be a new C standard if it didn''t give a
new meaning to the word `static''."
--Peter Seebach on C99


这篇关于如何初始化和打印unicode字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆