如何无休止地继续循环,直到用户按任意键。 [英] how to endlessly continue the loop until user presses any key.

查看:69
本文介绍了如何无休止地继续循环,直到用户按任意键。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

void PrintIntro(){
	
system("color 0E");	
cout<<"\n \n \n \n \n \n \n \n";
system("color 01");
cout<<"    MM         MM   OOOOOO  NN     N  OOOOOO  PPPPPP   OOOOOO  LL   YY      YY "<<endl;
system("color 02");
cout<<"    M M       M M  O      O N N    N O      O P     P O      O LL    YY    YY  "<<endl;
system("color 03");
cout<<"    M  M     M  M  O      O N  N   N O      O P     P O      O LL     YY  YY   "<<endl;
system("color 04");
cout<<"    M   M   M   M  O      O N   N  N O      O PPPPPP  O      O LL       YY     "<<endl; 
system("color 05");
cout<<"    M    M M    M  O      O N    N N O      O PP      O      O LL       YY     "<<endl; 
system("color 06");
cout<<"    M     M     M   OOOOOO  N     NN  OOOOOO  PP       OOOOOO  LLLLLL   YY     "<<endl;	

cout<<"\n \n \n \n \n \n \n   ";
system("color 08");
cout<<"\n                    PRESS ANY KEY TO START SIMULATION";
getch();
	system("cls");

}





我想循环消息,直到用户按下键盘上的任意键。我怎么能这样做?



i want to loop the message until a user press any key on the keyboard. how can i do this?

推荐答案

您可以使用异步键盘输入,但它依赖于平台,例如Windows提供 _ kbhit [ ^ ]功能。

另一种方法是在一个单独的线程上等待同步输入。
You may use asynchronous keybaard input, but it's platform dependant, for instance Windows provides the _kbhit[^] function.
Another approach would be waiting for the synchronous input on a separate thread.


很难猜到你想要什么,但无论如何!请尝试下面,看看这是否是你想要的。



Its pretty hard to guess what you want but anyway! Try below and see if this is what you want.

void PrintIntro(){

do
{
    system("color 0E");	
    cout<<"\n \n \n \n \n \n \n \n";
    system("color 01");
    cout<<"    MM         MM   OOOOOO  NN     N  OOOOOO  PPPPPP   OOOOOO  LL   YY      YY "<<endl;
    system("color 02");
    cout<<"    M M       M M  O      O N N    N O      O P     P O      O LL    YY    YY  "<<endl;
    system("color 03");
    cout<<"    M  M     M  M  O      O N  N   N O      O P     P O      O LL     YY  YY   "<<endl;
    system("color 04");
    cout<<"    M   M   M   M  O      O N   N  N O      O PPPPPP  O      O LL       YY     "<<endl; 
    system("color 05");
    cout<<"    M    M M    M  O      O N    N N O      O PP      O      O LL       YY     "<<endl; 
    system("color 06");
    cout<<"    M     M     M   OOOOOO  N     NN  OOOOOO  PP       OOOOOO  LLLLLL   YY     "<<endl;	
     
    cout<<"\n \n \n \n \n \n \n   ";
    system("color 08");
    cout<<"\n                    PRESS ANY KEY TO START SIMULATION";
    getch();
    	system("cls");
     
    }while(getchar()!='\n')
} 


这篇关于如何无休止地继续循环,直到用户按任意键。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆