SIGINT处理和getline

我写了这个简单的程序:

void sig_ha(int signum) { cout<<"received SIGINT\n"; } int main() { string name; struct sigaction newact, old; newact.sa_handler = sig_ha; sigemptyset(&newact.sa_mask); newact.sa_flags = 0; sigaction(SIGINT,&newact,&old); for (int i=0;i<5;i++) { cout<<"Enter text: "; getline(cin,name); if (name!="") cout<<"Text entered: "<<name; cout<<endl; } return 0; } 

如果我在程序等待input时按下ctrl-c,则会得到以下输出:
input文字:收到SIGINT

input文字:
input文字:
input文字:
input文字:

(程序继续循环而不等待input)

我该怎么办?

Solutions Collecting From Web of "SIGINT处理和getline"