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

问题描述

限时删除!!

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

Here's a little program. I knowit's not unicode, but the product I'm working on is 14yrs old, so it'sjust 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 justfine, but built from visual studio 2008 the characters no longerround-trip.

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

For example, after the setlocale call, ALT+252 shows SUPERSCRIPTLATIN SMALL LETTER N as expected from cp437. And the byte from gets isxFC as expected. But when you give xFC to printf, it displays as LATINSMALL 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 thaton a completely default system, using basic calls likegets/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 scaredof 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 andall latin1 is legal. We've already gone to a lot of trouble to avoidbest-fitting when printing to the console, and the new behaviourdestroys that.

推荐答案

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.


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

1403页,肝出来的..

09-06 22:05