Beep ( )

How do I make C++ beep ( ) working on my Mac. I know it's stupid but I add windows.h. My code is here

#include <iostream>
#include <cstdlib>
#include <windows.h>
#include <fstream>
using namespace std;

int main ( )
{
// Three needed variables for the music
int frequency, duration, sleep;

// Create a text file to read music frequency, duration and sleeptime
ifstream lab1( "lab1.txt" );

// Check file is open or not
if ( lab1.is_open( ) )
{
cout << "File is opened" << endl;
cout << "Music is started" << endl;

while ( !lab1.eof( ) ) // Do needed stuff to the end of file
{
lab1 >> frequency >> duration >> sleep;
Beep ( frequency, duration ); // API, Read frequency and duration
Sleep ( sleep ); // API, Reads sleep time

}
}

// Display an error message that file ( lab1.txt ) was unable to open
else
{
cout << "Error, unable to open the file" << endl;
}

lab1.close( ); // Close the file

return 0;
}
The Microsoft-specific header file windows.h and the associated libraries do not exist on Apple platforms.
Try instead

1
2
# include <cstdlib>
int main() { std::system("tput bel"); }


If the terminal bell isn't sufficient (it looks like it isn't), you might check the reference....
Or this Stack overflow answer
http://stackoverflow.com/a/412922
Last edited on
Never knew Mac was related to UNIX/Linux. If it was Linux I would find the command line tool/command that made a beeping sound and install if it wasn't installed/existing already. Then call from std::system().
Last edited on
Topic archived. No new replies allowed.