简体   繁体   English

使用 cout 时发出奇怪的哔哔声

[英]Strange beep when using cout

today when I was working on some code of mine I came across a beeping sound when printing a buffer to the screen.今天,当我在处理我的一些代码时,在将缓冲区打印到屏幕时遇到了哔哔声。 Here's the mysterious character that produces the beep: '' I don't know if you can see it, but my computer beeps when I try to print it like this:这是产生哔哔声的神秘字符:''我不知道你是否能看到它,但是当我尝试像这样打印它时,我的计算机发出哔哔声:

cout<<(char)7<<endl;

Another point of interest is that the 'beep' doesn't originate from my on board beeper, but from my headphone/speaker另一个有趣的点是“哔”声不是来自我的机载蜂鸣器,而是来自我的耳机/扬声器

Is this just my computer or there something wrong with the cout function?这只是我的电脑还是 cout 功能有问题?

EDIT:编辑:

But then why does printing this character produce the beep sound?但是为什么打印这个字符会产生哔声呢? does that mean that I could send other such characters through the cout function to produce different effects?这是否意味着我可以通过 cout 函数发送其他此类字符以产生不同的效果?

0x7 is the ASCII character that produces a 'bleep' sound. 0x7 是产生“哔”声的 ASCII 字符。 It is a non-printable character.它是一个不可打印的字符。 Here is a full list of the ASCII characters and their codes: http://www.asciitable.com/以下是 ASCII 字符及其代码的完整列表: http : //www.asciitable.com/

Edit: The sound can be used for a veritable melange of things.编辑:声音可用于名副其实的混合事物。 However you cannot really produce other effects by sending other pieces of data through.但是,您无法通过发送其他数据来真正产生其他效果。 In the table in the link above anything on the list below 0x20 (32 decimal) is a non-printable character.在链接上方的表格中,0x20(十进制32)下方的列表中的任何内容都是不可打印的字符。 They can have different effects depending on where the data is actually output.根据实际输出数据的位置,它们可以产生不同的效果。

Basically you could just write a loop to output 0-(whatever number you wish to stop at) to experiment and see what you can get.基本上,您可以编写一个循环来输出 0-(您希望停止的任何数字)以进行实验并查看您能得到什么。

In ASCII the character 7 is the "bell" character that signals to the terminal that it should beep.在 ASCII 中,字符 7 是“铃”字符,它向终端发出信号,表明它应该发出哔哔声。

EDIT: To answer your followup question, it's really just for historical reasons.编辑:为了回答您的后续问题,这真的只是出于历史原因。 The old teletype terminals needed a way to alert the operator of an incoming message so a bell was used.旧的电传终端需要一种方法来提醒操作员有传入消息,因此使用了铃铛。 The bell character told the terminal to ring the bell rather than print a character.铃声字符告诉终端响铃而不是打印字符。

Modern terminal emulators do essentially the same thing, although they usually have an option to replace the audible bell with a visual one.现代终端模拟器基本上做同样的事情,尽管它们通常可以选择用可视铃声替换可听铃声。

char 7 is the ASCII code for BELL. char 7 是 BELL 的 ASCII 码。 Writing this character to the console causes the computer to emit a beep.将此字符写入控制台会导致计算机发出哔哔声。 It is perfectly normal.这是完全正常的。

chat 7 is actually a "beep" character and not a screen character. chat 7 实际上是一个“哔”字符而不是屏幕字符。 Although sometimes documentation may show a character, it's generally not something you can render visually.尽管有时文档可能会显示一个字符,但它通常不是您可以直观呈现的。

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

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