I was trying to print \a
but it shows nothing so I searched for this and found out it should have made a sound but it didn't either.
I am using code lite on Windows 8.
- How to print
\a
? - Where is that sound?
This is my code:
#include <iostream>
using namespace std;
int main()
{
cout <<"\a";
return 0;
}
How to produce bell sound
If you want to print'\a'
character to produce bell sound, you are already doing it the right way.If the system beep is disabled (depending on your OS/target system, steps to enable beep may be different), you won't hear any sound. For windows you can follow this tutorial to enable the beep sound. One of the method tutorial suggests is following (For windows 7, should be more or less similar in windows 8 also)
Also it is a legacy method to produce system beep, modern systems may not make a noise, and may instead make a visual indication (such as flashing the screen, or do nothing at all.) (From Wikipedia Bell character)
How to print
\a
thenIf you want to literally print
\a
use following\
is a delimiter character and\a
stands for ascii alarm or bell character.Using escape sequence
\\
will print the first\
character followed by the nexta
.Further readings:
1. String literal in C++
2. Escape sequences in C++