Strange beep when using cout
Asked Answered
C

4

6

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?

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?

Ceballos answered 15/1, 2011 at 19:25 Comment(2)
I am waiting for the punch line... ASCII code 7 is the system beep (Control-G).Habitual
You likely have a "Play system beeps through speakers" setting in your sound card configuration somewhere. If you turn that off, you should hear 0x7 the way it was meant to be heard, as an uncomfortably loud sawtooth wave coming from the cheapest speaker your PC manufacturer could find.Carbonize
V
11

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

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.

Versicular answered 15/1, 2011 at 19:27 Comment(0)
I
13

0x7 is the ASCII character that produces a 'bleep' sound. It is a non-printable character. Here is a full list of the ASCII characters and their codes: 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. 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.

Ichthyoid answered 15/1, 2011 at 19:28 Comment(0)
V
11

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

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.

Versicular answered 15/1, 2011 at 19:27 Comment(0)
A
3

char 7 is the ASCII code for BELL. Writing this character to the console causes the computer to emit a beep. It is perfectly normal.

Aliment answered 15/1, 2011 at 19:27 Comment(0)
F
3

chat 7 is actually a "beep" character and not a screen character. Although sometimes documentation may show a character, it's generally not something you can render visually.

Fecteau answered 15/1, 2011 at 19:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.