Getting error sound without including any?

Viewed 313

I'm following a book and currently learning about pointers and such however when i run this code i also get a wierd error sound. It's kinda cool that it does but i don't know why it's called and the book didn't say anything about (possibly cause the book is decently old now). The sound occurs when i call for 'ErrorMessage'. Is that some kind of easter egg cause i don't remember including any audio libaries?

#include <iostream>

ErrorMessage(char* msg)
{
    std::cout << "\aError:" << msg << std::endl;
}

int main()
{
    char* ep = "Invalid Input";

    ErrorMessage(ep);

    char msg[] = "Disk Failure";

    ErrorMessage(msg);

    ErrorMessage("Timeout");
}
4 Answers

You have used an escape sequence when you've typed that backslash in your std::cout literal.

\a is a very old-fashioned way of sending a beep signal to your terminal (called the BEL character), assuming your console (i.e. the thing that you used to launch your application) supports beeping.

\a is the control character for a bell sound, so printing it to std::cout will produce one; exactly what ErrorMessage() does:

std::cout << "\aError:" << msg << std::endl; // make a beep then print "Error: <msg>"

\a (the a stands for alert)is the encoding for the ASCII BEL character, which will cause the terminal bell to be rung when it is output, assuming your terminal software or hardware supports such functionality.

Its because of

 std::cout << "\aError:" << msg << std::endl;

Notice that \a.
\a is an escape character which is audible alert which is generating that sound

Related