C不打印"┌──┐"字符正确 [英] c doesn't print "┌──┐" character correctly

查看:194
本文介绍了C不打印"┌──┐"字符正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午好,我面临着我的C code的一个问题,我不知道是什么原因造成的。

Good afternoon, I'm facing a problem on my c code and I don't know what is causing it.

每当我尝试打印字符这样的:┌──┐我的程序只是简单地打印一些奇怪的字符,就像这个截图:

Every time I try to print characters like these: "┌──┐" my program simply prints some strange characters, like on this screenshot:

我端子输出的截图

我使用Qt创建者在Windows上,使用Qt版本5.5.0 MSVC 64位。编译器是Microsoft Visual C ++编译器12.0(AMD64)。

I'm using Qt Creator on Windows, with Qt version 5.5.0 MSVC 64 bits. The compiler is the Microsoft Visual C++ Compiler 12.0 (amd64).

我试图改变语言环境,但没有成功。我发现打印这些字符的唯一办法就是将它们定义为int的ASCII code和打印这些变量,但它导致了一些非常广泛的和丑陋的代码,像这样:

I tried changing the locale but with no success. The only way I found to print these characters was to define them as int variables with the ASCII code and printing them, but it led to some really extensive and ugly coding, like this:

int cSupEsq = 218;  //'┌'
int cSupDir = 191;  //'┐'
int cInfEsq = 192;  //'└'
int cInfDir = 217;  //'┘'
int mVert = 179;    //'│'
int mHor = 196;     //'─'
int espaco = 255;   //' '
int letraO = 111;   //'o'

//Inicia limpando a tela da aplicação
clrscr();

//Linha 1
printf("%c", cSupEsq);
for (i = 1; i < 79; i++) { printf("%c", mHor); }
printf("%c", cSupDir);

有没有什么办法可以让程序正确对待这些字符?这可能是造成这个问题?

Is there any way I can make the program treat these characters correctly? What could be causing this problem?

推荐答案

您的解决方案使用OEM code点是正确的道路要走,codePAGE四百三十七分之八百五是默认的code页面为控制台,因此应该工作。你也可以使用 SetConsoleOutputCP 以确保正确的code页面用于控制台。

Your solution to use the OEM code points is the right way to go, codepage 850/437 is the default code page for the console and therefore should work. You could also use SetConsoleOutputCP to ensure the correct code page is used for the console.

说到这里,发生了什么事,当你不使用你的解决方法是源文件正在使用不同的codePAGE即保存。没有codePAGE四百三十七分之八百五十○。源$ C ​​$ C的记忆重新presentation是单向code(可能是UTF-8),当您保存该文件的字符在内存中再presentation被映射到目标$ C $ç页的文件。

Having said that, what is happening when you do not use your workaround is that the source file is being saved using a different codepage ie. not codepage 850/437. The in memory representation of the source code is Unicode (probably UTF-8), when you save the file the in memory representation of the characters are mapped to the target code page for the file.

你可以做的是使用437分之850codePAGE作为目标来保存文件,我不知道你是怎么Qt Creator中做到这一点(如果可以的话),在Vi​​sual Studio例如你可以保存按钮选择向下箭头,然后选择保存与编码,然后就可以继续选择目标codePAGE,你的情况code 850页这将确保在内存code点是正确映射到要编译的文件。

What you can do is to save the file using the 850/437 codepage as the target, I don't know how you do this in Qt Creator (If you can at all), in Visual Studio for example you can select the down arrow on the Save button and select "Save with encoding", you can then proceed to select the target codepage, in your case code page 850. This will ensure that the in memory code points are mapped correctly to the file to be compiled.

我希望有助于解释这个问题。

I hope that helps explain the issue.

这篇关于C不打印&QUOT;┌──┐&QUOT;字符正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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