make sounds (beep) with c++

前端 未结 12 655
暗喜
暗喜 2020-11-29 04:08

How to make the hardware beep sound with c++?

Thanks

12条回答
  •  我在风中等你
    2020-11-29 04:42

    There are a few OS-specific routines for beeping.

    • On a Unix-like OS, try the (n)curses beep() function. This is likely to be more portable than writing '\a' as others have suggested, although for most terminal emulators that will probably work.

    • In some *BSDs there is a PC speaker device. Reading the driver source, the SPKRTONE ioctl seems to correspond to the raw hardware interface, but there also seems to be a high-level language built around write()-ing strings to the driver, described in the manpage.

    • It looks like Linux has a similar driver (see this article for example; there is also some example code on this page if you scroll down a bit.).

    • In Windows there is a function called Beep().

提交回复
热议问题