Is there a way to play a system beep on Mac OS?

浪尽此生 提交于 2019-11-28 08:12:01

问题


Is there a way to play a system beep on Mac OS using C++ and Xcode? I understand that I need to use a library. Is there a library that works across both the Mac and Windows platforms?


回答1:


I think you probably want to use NSBeep.


NSBeep

Plays the system beep.

#include <AppKit/AppKit.h>

void NSBeep (void);

This seems to work OK for a command line tool:

#include <AppKit/AppKit.h>
#include <iostream>

using namespace std;

int main(void)
{
    cout << "Hello world !" << endl;
    NSBeep ();
    return 0;
}

$ g++ -Wall -framework AppKit beep.cpp -o beep
$ ./beep



回答2:


The cross platform way to play a beep is std::cout << "\007";. I had been trying to play it by passing in a char and then decrementing until 7. That didn't work. Explicitly outputting the code did work though.



来源:https://stackoverflow.com/questions/7408785/is-there-a-way-to-play-a-system-beep-on-mac-os

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!