使用cout时发出奇怪的嘟嘟声 [英] Strange beep when using cout

查看:235
本文介绍了使用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

这是我的电脑还是cout功能有问题?

Is this just my computer or there something wrong with the cout function?

但是为什么打印这个字符会产生蜂鸣声?

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?

推荐答案

在ASCII中,字符7是bell字符表示终端应该发出哔声。

In ASCII the character 7 is the "bell" character that signals to the terminal that it should beep.

编辑:为了回答你的后续问题,这只是因为历史原因。旧的电传终端需要一种方式来提醒操作者输入的消息,因此使用了铃。

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.

这篇关于使用cout时发出奇怪的嘟嘟声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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