宽字符输入/输出 [英] Wide character input/output

查看:54
本文介绍了宽字符输入/输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[当前消息编码设置为Unicode(UTF-8),因为它

包含希腊语]

以下代码无法按预期工作:

#include< wchar.h>

#include< locale.h>

#include< stdio.h>

#include< stddef.h>


int main()

{

char * p = setlocale( LC_ALL,希腊语);


wchar_t输入[50];


if(!p)

printf(" NULL return!\ n");


fgetws(输入,50,标准输入);


wprintf(L" ;%s \ n",输入);


返回0;

}

在Linux下:

[john @ localhost src] $ ./foobar-cpp

测试

T

[john @ localhost src] $

[john @ localhost src] $ ./foobar-cpp

????? o?1 ???? ????? 1?o ?? < br $> b $ b ????

[john @ localhost src] $


在MS Visual C ++ 2008 Express下:


测试

测试


按任意键继续。 。 。

????? o?1 ???? ????? 1?o ??

???????μ??? ?

按任意键继续。 。 。

我错过了什么吗?

解决方案

./ foobar-cpp

测试

T

[john @ localhost src]




[john @ localhost src]

./ foobar-cpp

????? o?1 ???? ????? 1?o ??

????

[john @ localhost src]


[The current message encoding is set to Unicode (UTF-8) because it
contains Greek]
The following code does not work as expected:
#include <wchar.h>
#include <locale.h>
#include <stdio.h>
#include <stddef.h>

int main()
{
char *p= setlocale( LC_ALL, "Greek" );

wchar_t input[50];

if (!p)
printf("NULL returned!\n");

fgetws(input, 50, stdin);

wprintf(L"%s\n", input);

return 0;
}
Under Linux:
[john@localhost src]$ ./foobar-cpp
Test
T
[john@localhost src]$
[john@localhost src]$ ./foobar-cpp
?????o?1???±?????1?o??
???
[john@localhost src]$


Under MS Visual C++ 2008 Express:

Test
Test

Press any key to continue . . .
?????o?1???±?????1?o??
???????μ????

Press any key to continue . . .
Am I missing something?

解决方案

./foobar-cpp
Test
T
[john@localhost src]



[john@localhost src]


./foobar-cpp
?????o?1???±?????1?o??
???
[john@localhost src]


这篇关于宽字符输入/输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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