好吧,我知道CLD清除方向标志和STD设置方向标志.但是设置和清除方向标志的重点是什么?
#include <iostream>
#include <conio.h>
int main(){
while(true){
printf("Hello World!\n");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
上述程序将无休止地打印"Hello World".我希望一旦用户按下键盘上的"T"键,程序就会终止.关于如何做到这一点的任何线索.......
如果我这样做的话
#include <iostream>
#include <conio.h>
int main(){
char key;
while(true){
printf("Hello World!\n");
key = getch();
if(key=='T' || key=='t'){
break;
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
然后程序将始终等待用户按下一个键.我希望程序继续执行而不会暂停,一旦用户按下任何特定的键,程序就会终止.
顺便说一下,我的操作系统是linux(debian),我正在使用gcc.