关闭 C++ 控制台应用程序时会发生什么

What happens when you close a c++ console application(关闭 C++ 控制台应用程序时会发生什么)
本文介绍了关闭 C++ 控制台应用程序时会发生什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想这个问题说明了一切,但是,如果有人关闭了 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++ 控制台应用程序时会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Prevent class inheritance in C++(防止 C++ 中的类继承)
Why should I declare a virtual destructor for an abstract class in C++?(为什么要在 C++ 中为抽象类声明虚拟析构函数?)
Why is Default constructor called in virtual inheritance?(为什么在虚拟继承中调用默认构造函数?)
C++ cast to derived class(C++ 转换为派生类)
C++ virtual function return type(C++虚函数返回类型)
Is there any real risk to deriving from the C++ STL containers?(从 C++ STL 容器派生是否有任何真正的风险?)