問題描述
我想這個問題說明了一切,但是,如果有人關閉了 C++ 控制臺應用程序會發生什么?如,單擊頂角的x".它會立即關閉嗎?它會拋出某種異常嗎?這是未定義的行為嗎?
I guess the question says it all, but, what happens if someone closes a c++ console app? As in, clicks the "x" in the top corner. Does it instantly close? Does it throw some sort of exception? Is it undefined behavior?
推薦答案
關閉帶有x"在頂角的 c++ 控制臺應用程序會拋出一個 CTRL_CLOSE_EVENT
,如果您設置,您可以捕獲和處理使用 SetConsoleCtrlHandler 函數的控制處理程序.在那里,您可以覆蓋關閉功能并執行您想做的任何事情,然后仍然可以選擇執行默認行為.
Closing a c++ console app with the "x" in the top corner throws an CTRL_CLOSE_EVENT
which you could catch and process if you set a control handler using the SetConsoleCtrlHandler function. In there you could override the close functionality and perform whatever you wished to do, and then optionally still perform the default behavior.
這篇關于關閉 C++ 控制臺應用程序時會發生什么的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!