You are here:

C++/making a "beep" sound


Hi there,
I was just wondering how to make a "beep" sound
from inside my C++ code. I have already tried
both, cout << "\a"; and, cout << '0x07'; Neither
of them worked. I also used cerr and printf()
but nothing seems to be working. Is there
anything else I can try? I'm running SuSe on a
Linux box. I also know that my computer CAN beep
because I've heard it before.

Thanks so much in advance,

Well I cannot say for sure why your program does not do what you wish. I have just tried a similar program on my SuSE Linux box - running in a terminal session under the GNOME desktop and it worked fine for me so I can only suggest that it is your system setup (hardware and/or software) or the terminal emulation you are using does not support mapping the ASCII alert character to a sound or your code is not doing what you think.

I would suggest also outputting some text - maybe "Beep!\a\n" - to ensure your program is doing what you think. When you are sure all is running as expected you can remove the additional text.

To check to see if your terminal/console supports alert beeps type in Ctrl-G when at the command prompt (Ctrl-G is character number 7 - note that G is the seventh character of the alphabet - so line feed (character 10) is Ctrl-J and carriage return (character 13) is Ctrl-M and tab (character 9) is Ctrl-I etc...). Note that this does not seem to work on Windows “DOS box” command shells – my Windows 2000 consoles just print ^G – not useful. However it does seem to work for the consoles for the Cygwin UNIX like environment under Windows.

One thing that caught me out (it is gone 1 am here in the UK and I want my bed!) is that I used the name "test" for my program and when I first tried to run it using just test nothing seemed to happen, even when I added the text "Beep!" to the control characters to be output. After a bit I realised that maybe another program or command was being run instead - so I ran the program using ./test instead and got the results I wanted. test is also a standard utility program used in scripts with the likes of if to test for various file conditions - see the man page or info entry for test.

./test forced the command interpreter to look in the current directory for the named executable, otherwise it uses the PATH environment variable which probably does not look in the current directory (i.e. in . ) first. In fact on my system under my user account the current directory is around the 9th out of 11 places listed to search.

Hope this gives you some ideas and directions to check out. Oh and I hope you fix the problem. Good luck, I'm off to bed...  


All Answers

Answers by Expert:

Ask Experts


Ralph McArdell


I am a software developer with more than 15 years C++ experience and over 25 years experience developing a wide variety of applications for Windows NT/2000/XP, UNIX, Linux and other platforms. I can help with basic to advanced C++, C (although I do not write just-C much if at all these days so maybe ask in the C section about purely C matters), software development and many platform specific and system development problems.


My career started in the mid 1980s working as a batch process operator for the now defunct Inner London Education Authority, working on Prime mini computers. I then moved into the role of Programmer / Analyst, also on the Primes, then into technical support and finally into the micro computing section, using a variety of 16 and 8 bit machines. Following the demise of the ILEA I worked for a small company, now gone, called Hodos. I worked on a part task train simulator using C and the Intel DVI (Digital Video Interactive) - the hardware based predecessor to Indeo. Other projects included a CGI based train simulator (different goals to the first), and various other projects in C and Visual Basic (er, version 1 that is). When Hodos went into receivership I went freelance and finally managed to start working in C++. I initially had contracts working on train simulators (surprise) and multimedia - I worked on many of the Dorling Kindersley CD-ROM titles and wrote the screensaver games for the Wallace and Gromit Cracking Animator CD. My more recent contracts have been more traditionally IT based, working predominately in C++ on MS Windows NT, 2000. XP, Linux and UN*X. These projects have had wide ranging additional skill sets including system analysis and design, databases and SQL in various guises, C#, client server and remoting, cross porting applications between platforms and various client development processes. I have an interest in the development of the C++ core language and libraries and try to keep up with at least some of the papers on the ISO C++ Standard Committee site at


©2017 All rights reserved.