make sounds (beep) with c++

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

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

Thanks

12条回答
  •  天命终不由人
    2020-11-29 04:44

    If you're using Windows OS then there is a function called Beep()

    #include  
    #include  // WinApi header 
    
    using namespace std;
    
    int main() 
    { 
        Beep(523,500); // 523 hertz (C5) for 500 milliseconds     
        cin.get(); // wait 
        return 0; 
    }
    

    Source: http://www.daniweb.com/forums/thread15252.html

    For Linux based OS there is:

    echo -e "\007" >/dev/tty10
    

    And if you do not wish to use Beep() in windows you can do:

    echo "^G"
    

    Source: http://www.frank-buss.de/beep/index.html

提交回复
热议问题