在C++中放慢滚动速度
Slow Down Scrolling in C++?
这是我为显示单词"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);
}
}
看看其中一个可以暂时挂起线程或进程的API,比如sleep()或delay()。
在Linux上,有sleep()和usleep()。在带有Borland的MSDOS上,存在delay(),在Windows上,存在sleep()。
您可以在每个字母或行之间使用此函数:
#include <unistd.h>
usleep( microseconds );
来源:睡眠毫秒
请参阅:http://linux.die.net/man/3/usleep
相关文章:
- 使用一个考虑到std::map中键值的滚动或换行的键
- 为什么在读取文件大小时文件IO速度会发生变化
- 为什么std::condition_variable notify_all的工作速度比notify_one快(对于随机请
- 文件系统:复制功能的速度秘诀是什么
- QScrollArea:由垂直滚动条引起的水平滚动条
- 跟踪滚动条上的鼠标事件
- 学习多线程C++:添加线程不会使执行速度更快,即使它看起来应该
- 如何在不使用滚动条的情况下使视图更改
- 如何为对象生成滚动效果?
- 在C++中使用并行化的预期速度是多少(不是 OpenMp,而是 <thread>)
- 如何模拟不同边数的骰子滚动?
- 两个连续的 OpenMP 并行区域会相互减慢速度
- 如何初始化升压滚动窗口累加器?
- 查找标准::hash_map与标准::矢量的速度
- 加快在C++中读取/处理日志文件的速度
- 实现包含多个 QQuickPaintedItems 的 QQuickView 的滚动
- 为什么这些算法的运行速度比它们应该的要快?
- 通过水平滚动条更改标签
- 在C++中放慢滚动速度
- QtQAbstractItemModel在树视图中滚动时速度较慢