make sounds (beep) with c++

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

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

Thanks

12条回答
  •  一向
    一向 (楼主)
    2020-11-29 04:36

    You could use conditional compilation:

    #ifdef WINDOWS
    #include 
    void beep() {
      Beep(440, 1000);
    }
    #elif LINUX
    #include 
    void beep() {
      system("echo -e "\007" >/dev/tty10");
    }
    #else
    #include 
    void beep() {
      cout << "\a" << flush;
    }
    #endif
    

提交回复
热议问题