控制台中的重音字符 [英] accented characters in the console

查看:125
本文介绍了控制台中的重音字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个小程序.我知道 它不是unicode,但是我正在使用的产品已有14年的历史了,所以它是 太晚了.

Here's a little program. I know it's not unicode, but the product I'm working on is 14yrs old, so it's just too late for that.

#include< iostream>

#include <iostream>

void info()
{
char line [1024];
printf("\ n通过gets()输入");
gets(line);
printf (通过printf()%s \ n回显,行);
}

void info()
{
  char line[1024];
  printf("\n Input via gets() ");
  gets(line);
  printf(" Echo via printf() %s\n",line);
}

int main(int argc,char ** argv)
{
info();
setlocale(LC_CTYPE,");
info();
返回0 ;
}

int main(int argc, char** argv)
{
  info();
  setlocale(LC_CTYPE,"");
  info();
  return 0;
}

因此,在我的基于Visual Studio 98的dos控制台上,这仅能正常工作 很好,但是是从Visual Studio 2008构建的,角色不再 往返.

So, on my dos console, built from visual studio 98, this works just fine, but built from visual studio 2008 the characters no longer round-trip.

例如,在setlocale调用之后,ALT + 252显示SUPERSCRIPT 拉丁文小写字母N,如cp437所预期.从获取的字节是 xFC符合预期.但是,当您将xFC赋予printf时,它将显示为LATIN cp1252会期望带有DIAERESIS的小写字母U.

For example, after the setlocale call, ALT+252 shows SUPERSCRIPT LATIN SMALL LETTER N as expected from cp437. And the byte from gets is xFC as expected. But when you give xFC to printf, it displays as LATIN SMALL LETTER U WITH DIAERESIS as would be expected from cp1252.

现在,我意识到我可以通过使用以下方法来解决此问题 改为使用ReadConsole/WriteConsole,但这并不是有点阴险 在完全默认的系统上,使用诸如 gets/printf/setlocale,简单的IO不会往返吗?

Now I realize that I can work around this by using  ReadConsole/WriteConsole instead, but isn't is a little insidious that on a completely default system, using basic calls like gets/printf/setlocale, simple IO doesn't round-trip?

也许我想念一些东西,但似乎有人故意让他们受苦.

Maybe I'm missing something, but it seems like someone has intentionally gone out of their way to make me suffer.

我想知道为什么.

谢谢.

P.S.为什么要调用setlocale?因为我们一直都有,他们很害怕 如果我们更改数据库驱动程序等将会发生什么.

P.S. why call setlocale? Because we always have, and they're scared of what will happen to the database drivers, etc. if we change it.

P.S.为什么要关心非ASCII?因为许多应用程序都与我们的数据库对话, 所有latin1都是合法的.我们已经避免了很多麻烦 打印到控制台时最合适的方式,以及新的行为

P.S. why care about non-ascii? Because many apps talk to our db and all latin1 is legal. We've already gone to a lot of trouble to avoid best-fitting when printing to the console, and the new behaviour destroys that.

推荐答案

迈克尔,

我已经运行了您发布的代码,效果很好.

但我无法完全理解您发布的以下段落:

Hi Michael,

I have run the code you posted , it works well.

But I could not fully understand the following paragraph you posted:

Michael Holtstrom说:

例如,在setlocale调用之后,ALT + 252如cp437所示显示SUPERSCRIPT LATIN SMALL LETTERN.和得到的字节是预期的xFC.但是,当您将xFC赋予printf时,它将显示为带有DIAERESIS的拉丁文小写字母U,如cp1252所期望的那样.

For example, after the setlocale call, ALT+252 shows SUPERSCRIPT LATIN SMALL LETTER N as expected from cp437. And the byte from gets is xFC as expected. But when you give xFC to printf, it displays as LATIN SMALL LETTER U WITH DIAERESIS as would be expected from cp1252.


这篇关于控制台中的重音字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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