Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error sound without including any?

Tags:

c++

audio

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");
}
like image 679
Adam Palmkvist Avatar asked Jan 20 '26 15:01

Adam Palmkvist


2 Answers

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

like image 138
Digvijaysinh Gohil Avatar answered Jan 22 '26 06:01

Digvijaysinh Gohil


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.

like image 41
Bathsheba Avatar answered Jan 22 '26 06:01

Bathsheba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!