简体   繁体   English

特殊字符C / C ++

[英]Special characters C/C++

When I compile the code below, using NetBeans, the output of the program is some strange characters in the terminal (teste á é õ). 当我使用NetBeans编译下面的代码时,程序的输出是终端中的一些奇怪字符(testeééõ)。 Unfortunately I could not find the solution for this. 不幸的是,我找不到解决方案。

Has anyone experienced this? 有人经历过吗? Know the solution? 知道解决方案吗?

#include <stdio.h> 
#include <locale.h> 

int main(int argc, char** argv) { 
setlocale(LC_ALL,""); 
printf("teste á é õ"); 
return (0); 
} 

My compiler is MinGW, my native language is Brazilian Portuguese. 我的编译器是MinGW,我的母语是巴西葡萄牙语。

样本配置和版本

output: 输出:

输出

They are not Ascii Characters. 它们不是ASCII字符。

ASCII characters 0-31 are various space characters and there is no standardized way to print them. ASCII字符0-31是各种空格字符,没有标准化的方式来打印它们。 This is an "extended ASCII table". 这是“扩展的ASCII表”。 There is no guarantee that those exact symbols will be printed on your particular platform. 不能保证这些确切的符号将被打印在您的特定平台上。

They work fine for me in Windows 7, tested with GCC and Embarcadero C++, both print those symbols. 它们在Windows 7上对我来说运行良好,并通过GCC和Embarcadero C ++测试,都可以打印这些符号。 But on another OS and/or compiler, different symbols or nothing at all might be printed. 但是在另一个OS和/或编译器上,可能会打印不同的符号或根本不打印任何内容。

Only ASCII characters 32 - 126 are guaranteed to be printable, and the same symbol, on all systems. 在所有系统上,只能保证ASCII字符32-126是可打印的,并且符号相同。

C++ is an English language and can only print the original ASCII code from English, some 3rd party libraries such as Curses let you get around this and print some non-ASCII ones found here: http://www.melvilletheatre.com/articles/ncurses-extended-characters/index.html C ++是一种英语语言,只能打印英语中的原始ASCII代码,某些第三方库(例如Curses)可以使您解决这个问题并打印一些非ASCII代码库, 网址为http : //www.melvilletheatre.com/articles/ ncurses-extended-characters / index.html

But for the most part, I can't see why you would want to print these characters since there is no practical purpose. 但是在大多数情况下,由于没有实际用途,所以我看不到为什么要打印这些字符。

Other explanation: You can't do this since the original ASCII code consists of 127 types. 其他说明:您不能执行此操作,因为原始ASCII代码包含127种类型。 Binary and stuff, different answer to the question, so just know their are only 127 possible letters allowed, more can be found here. 二进制和填充物,对问题的回答不同,所以只知道它们仅允许127个字母,在这里可以找到更多。 enwikipedia.org/wiki/ASCII and williamrobertson.net/documents/ascii.html (This one gives you what can actually be printed by C++) enwikipedia.org/wiki/ASCII和williamrobertson.net/documents/ascii.html(此代码为您提供了可以用C ++实际打印的内容)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM