How to use the \ escape sequence

I am learning C ++ using bash and Escape Sequences. I try to do a lot of exercises so that I can remember them better. Now, \ a should produce sound like a beep.

I am using the following code, but it seems that \ a does not work:

#include <iostream>
using namespace std;

int main ()

 {

   cout << "\a";

   return 0;

 }

      

I made a mistake? I only use it as a \ n sequence, is that wrong? Thank you!

New Details: I found it works in terminal, but it doesn't work in built-in terminal in Kate.

OS: I am using Ubuntu as a guest OS using Windows 7 as a host with VirtualBox. I'll post a version soon.

+3


source to share


2 answers


Whether the \a

beep beeps or not depends on where you write it. If you run this program on a Unix terminal, you will probably get sound. If you are using an IDE or a GUI terminal emulator, it may happen that you will not see or hear anything.



If you specify which terminal you are using (gnome-terminal? Apple Terminal.app?) Someone can help you configure it to play sound ...

+5


source


Run first sudo modprobe pcspkr

and then beep

should work.

If this works for you, then to enable pcspkr loading permanently edit the file /etc/modprobe.d/blacklist.conf

and comment out the line that saysblacklist pcspkr

...



As mentioned in the comment, Ubuntu does not beep at the terminal by default these days; the information posted above was taken from this answer .

After you have completed these steps, run the program again and check if the problem is fixed.

+1


source







All Articles