0

这是我写的代码,用来显示单词“Hello”,它会像广告牌一样滚动。我在这里发现了滚动太快的问题,如何使用循环方法减慢它的速度?感谢您的指导!

#include <iostream>
#include <cstdlib>
using namespace std;

void charH()
{
cout << "H   H"<<endl;
cout << "H   H"<<endl;
cout << "HHHHH"<<endl;
cout << "H   H"<<endl;
cout << "H   H"<<endl;
}   

void charE()
{
cout << "EEEEE"<<endl;
cout << "E    "<<endl;
cout << "EEEE "<<endl;
cout << "E    "<<endl;
cout << "EEEEE"<<endl;
}

void charL()
{
cout <<"L     "<<endl;
cout <<"L     "<<endl;
cout <<"L     "<<endl;  
cout <<"L     "<<endl;  
cout <<"LLLLL "<<endl;  
}

void charO()
{
cout <<" OOO "<<endl;
cout <<"O   O"<<endl;
cout <<"O   O"<<endl;
cout <<"O   O"<<endl;
cout <<" OOO "<<endl;
}   

void charEx()
{
cout <<"  !  "<<endl;
cout <<"  !  "<<endl;
cout <<"  !  "<<endl;
cout <<endl;
cout <<"  !  "<<endl;
}

 void displayAll()
{
charH();
cout<<endl;
charE();
cout<<endl;
charL();
cout<<endl;
charL();
cout<<endl;
charO();
cout<<endl;
charEx();
 }  

void Accept(char variable)
{
switch (variable)
{
    case 'H' : charH();
               break; 
    case 'E' : charE();
               break;   
    case 'L' : charL();
               break; 
    case 'O' :charO();
               break; 
    case '!' : charEx();
               break; 
    default : cout << " " << endl; system("pause"); break;
}
}

void AcceptAChar(char choice)
{
Accept(choice); 

}

void Accept6Char(char a, char b, char c, char d, char e, char f)
{
AcceptAChar(a);
cout << endl;
AcceptAChar(b);
cout << endl;
AcceptAChar(c);
cout << endl;
AcceptAChar(d);
cout << endl;
AcceptAChar(e);
cout << endl;
AcceptAChar(f);
}   

void rotate(char& a, char& b, char& c, char& d, char& e, char& f)
{
char temp = a;
a=b;
b=c;
c=d;
d=e;
e=f;
f=temp;
Accept6Char( a,  b,  c,  d,  e, f);

}   

int main()
{

char a = 'H';
char b = 'E';
char c = 'L';
char d = 'L';
char e = 'O';
char f = '!';

for(int i=0; i >=0; i=i++)
{
    system("cls");
    rotate(a, b, c, d, e, f);
}   

}
4

2 回答 2

1

看看其中一个用于暂时挂起线程或进程的 API,例如 sleep() 或 delay()。

在 Linux 上,有 sleep() 和 usleep()。在带有 Borland 的 MSDOS 上,有 delay(),对于 Windows,有 sleep()。

于 2013-08-10T16:15:33.940 回答
0

您可以在每个字母或行之间使用此功能:

#include <unistd.h>
usleep( microseconds );

来源:睡眠毫秒

见: http: //linux.die.net/man/3/usleep

于 2013-08-10T16:16:39.283 回答