版权声明:本文可能为博主原创文章,若标明出处可随便转载。 https://blog.csdn.net/Jailman/article/details/85250506
#include "pch.h"
#include <iostream>
#include <csignal>
#include <windows.h>
using namespace std;
int i;
void signalHandle(int signum)
{
cout << "Interrupt signal(" << signum << ")received" << endl;
i = signum;
}
int main()
{
//注册信号以及信号处理程序
signal(SIGINT, signalHandle);
while (1)
{
if (i == 2)
{
break;
}
cout << "hello..." << endl;
Sleep(1000);//暂停1s
}
system("pause");
return 0;
}
参考
https://blog.csdn.net/qq_28796345/article/details/51290493