Try including ncurses.h
#include <ncurses.h>
beep();
compile with the -lncurses flag
Reference : http://invisible-island.net/ncurses/man/curs_beep.3x.html
Also this question : make sounds (beep) with c++
Edit:
try this command line
sudo sh -c "echo -e '\a' > /dev/console"
Also try the code given at http://www.linuxplayer.org/2010/04/beep-your-pc-speaker-in-linux
int ms = 5000;
int freq = 440;
ioctl(fd, KDMKTONE, (ms<<16 | 1193180/freq));