Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Placing the \a on the output stream does not produce a sound

Tags:

c++

c

This was prompted by some experimenting with C/C++; neither the statement

printf("\a");

nor the statement

cout << "\a";

produce an audible bell sound. How is the \a supposed to function . . .

like image 582
ioil Avatar asked Sep 06 '10 21:09

ioil


1 Answers

Although the ASCII BEL control character has a well-defined meaning, its exact interpretation in your console is highly platform dependent. C defines \a as the escape sequence for the ASCII BEL character found at code 7 and sometimes known as Ctrl+G. In the good old days, this control code allowed the bell of a remote terminal to be rung to alert the remote operator that a message needed attention.

In modern systems, the bell has largely been replaced by other mechanisms. You console window (whether an xterm or similar on *nix or a Console Windows on Windows) now has the responsibility of doing something "sensible" with that control character. It also has the freedom to ignore it completely.

On Windows, you can achieve an audible alert by calling MessageBeep(), passing 0xffffffff to get a simple beep noise that uses no system resources, MB_OK or another MB_ICON* constant to get one of the system event sounds.

like image 188
RBerteig Avatar answered Oct 17 '22 17:10

RBerteig