如何在输入和输出期间连续闪烁特定文本? [英] How to blink particular text continuously all time during input and output?

查看:172
本文介绍了如何在输入和输出期间连续闪烁特定文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,在用户输入他的名字后闪烁欢迎。



当用户在写姓名时,欢迎不闪烁。当用户命中输入时,插入符进入while循环。然后,插入位置被设置回Welcome& cout印刷品'欢迎'与5颜色再次&



但是我希望Welcome随着程序的启动而不断闪烁。


$ b

 #$ b 

这个问题也很有可能会问 - 我们可以同时有两个插入符号/ include< iostream>
#include< conio.h>
#include< windows.h>
using namespace std;
int main(int argc,char ** argv)
{
int x,y,i; char name [10];
textcolor(10);
x = wherex(); y = wherey(); //插入符号将存储在x& y。
cout<<\t\t\t\tWelcome\\\
;
textcolor(15);
cout<<\\\
输入您的名称\\\
;
gets(name);
while(1)
{
for(i = 10; i <15; i ++)
{
textcolor(i)
gotoxy(x,y); //将光标转换到存储在x& y。
cout<<\t\t\t\tWelcome;
Sleep(300);
}
}
return 0;
}


解决方案

这个问题,它不是100%正确的答案。我只是发布这个答案只是为了给新手有点想法。

  #include< iostream> 
#include< conio.h>
#include< windows.h>
using namespace std;
int x,y,b,l,n = 0;
char c;
void blink()
{
{
int m;
for(m = 10; m <15; m ++)
{
textcolor(m);
gotoxy(x,y);
cout<<\t\t\t\tWelcome;
Sleep(60);
}
}
}
int main(int argc,char ** argv)
{
char i; int key_stroke;
textcolor(10);
x = wherex(); y = wherey();
cout<<\t\t\t\tWelcome\\\
;
textcolor(15);
cout<<\\\
输入您的名称\\\
;
l = wherex(); b = wherey();
z:
{
while(1)
{
if(!kbhit()))
{
blink
goto z;
}
else
{
i = _getch();
if(i == 13)
{
gotoxy(l + n,b + 1);
return 0;
}
textcolor(10);
gotoxy(l + n,b);
cout<< i; n = n + 1;
}
}
}
return 0;
}


Here is my code which blinks 'Welcome' after user enter his name.

'Welcome' does not blink when user is writing his name. As user hits enter then caret goes into the while loop. Then caret position is set back to the coordinates of 'Welcome' & cout prints 'Welcome' with 5 colors again & again so it seems that 'Welcome' is blinking.

But I want that 'Welcome' blinks continuously as the program starts.

So more likely this question also ask - can we have two caret/cursor at the same time ?

#include <iostream>
#include <conio.h> 
#include <windows.h>
 using namespace std;
 int main(int argc, char** argv)
 {
   int x,y,i;char name[10];
   textcolor(10);
   x=wherex();y=wherey();       //corrdinates of caret will be stored in x & y.
   cout<<"\t\t\t\tWelcome\n";
   textcolor(15);
   cout<<"\nEnter your name\n";
   gets(name);
   while(1)
   {
      for(i=10;i<15;i++)
      {
         textcolor(i);
         gotoxy(x,y);          //Transferring caret to the coordinates stored in x & y.
         cout<<"\t\t\t\tWelcome";
         Sleep(300);
      }
   }
   return 0;
 }

解决方案

I wrote a small code for this question , it's not 100% correct answer. I am just posting this answer just for giving little bit idea to newbie.

#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
int x,y,b,l,n=0;
char c;
void blink()
{
    {
        int m;
        for(m=10;m<15;m++)
        {
            textcolor(m);
            gotoxy(x,y);
            cout<<"\t\t\t\tWelcome";
            Sleep(60);
        }
   }
}
int main(int argc, char** argv)
{
   char i;int key_stroke;
   textcolor(10);
   x=wherex();y=wherey();
   cout<<"\t\t\t\tWelcome\n";
   textcolor(15);
   cout<<"\nEnter your name\n";
   l=wherex();b=wherey();
   z:
   {
     while (1)
     {
          if(!(_kbhit()))
        {
               blink();
                 goto z;
        }
        else 
          {
             i=_getch();
             if(i==13)
             {
                gotoxy(l+n,b+1);
                    return 0;
               }
               textcolor(10);
               gotoxy(l+n,b);
               cout<<i;n=n+1;
          }
     }
   }
   return 0;
}

这篇关于如何在输入和输出期间连续闪烁特定文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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