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.
\a
?This is my code:
#include <iostream>
using namespace std;
int main()
{
cout <<"\a";
return 0;
}
'\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)
Device Manager > View menu > show hidden devices > Non-Plug and Play Drivers > Beep > double click or right click and properties > Driver tab > Startup > Type > Change from disabled to some other mode (system for example)
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)
\a
thenIf you want to literally print \a
use following
cout <<"\\a";
\
is a delimiter character and \a
stands for ascii alarm or bell character.
Using escape sequence \\
will print the first \
character followed by the next a
.
"\a"
is const char 2 with values\a
and'\0'
"\\a"
in const char 3 with values\
,'a'
and'\0'
Further readings:
1. String literal in C++
2. Escape sequences in C++
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With