简体   繁体   English

C ++无限标志

[英]C++ Infinity Sign

Hello I was just wondering how I can display the infinity (∞) in C++? 您好我只是想知道如何在C ++中显示无穷大(∞)? I am using CodeBlocks. 我正在使用CodeBlocks。 I read couple of Q&A's on this topic but I'm a newbie at this stuff, especially with Hex coding and stuff. 我在这个主题上阅读了几个关于Q&A的内容,但我是这方面的新手,尤其是Hex编码和东西。 What do I have to include and what do I type out exactly. 我需要包括什么以及我要准确输入什么内容。 If someone can write the code and explain it, that'd be great! 如果有人可以编写代码并解释它,那就太好了! Thanks! 谢谢!

The symbol is not part of the ASCII code . 该符号不是ASCII代码的一部分。 However, in the code page 437 (most of the time the default in Windows Command Prompt with English locales/US regional settings) it is represented as the character #236. 但是,在代码页437中(大多数情况下,Windows命令提示符中的默认值为英语区域设置/美国区域设置),它表示为字符#236。 So in principle 所以原则上

std::cout << static_cast<unsigned char>(236);

should display it, but the result depends on the current locale/encoding. 应该显示它,但结果取决于当前的语言环境/编码。 On my Mac (OS X) it is not displayed properly. 在我的Mac(OS X)上,它无法正常显示。

The best way to go about it is to use the UNICODE set of characters (which standardized a large amount of characters/symbols). 最好的方法是使用UNICODE字符集(标准化大量字符/符号)。 In this case, 在这种情况下,

std::cout << "\u221E"; 

should do the job, as the UNICODE character #221 represents inf . 应该做的工作,因为UNICODE字符#221代表inf

However, to be able to display UNICODE, your output device should support UTF encoding. 但是,为了能够显示UNICODE,您的输出设备应支持UTF编码。 On my Mac, the Terminal uses UTF, however Windows Command Prompt still uses the old ASCII encoding CodePage 437 (thanks to @chris for pointing this out). 在我的Mac上,终端使用UTF,但是Windows命令提示符仍然使用旧的ASCII编码CodePage 437(感谢@chris指出这一点)。 According to this answer , you can change to UNICODE by typing 根据这个答案 ,您可以通过键入更改为UNICODE

chcp 65001

in a Command Prompt. 在命令提示符中。

You can show it through its UNICODE 您可以通过其UNICODE显示它

∞ has the value: \∞ ∞的值为: \∞

You can show any character from the Character Map by its unicode. 您可以通过其unicode显示Character Map中的任何字符。

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

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