[c/c++]在使用循环去查询消息等操作时加入Sleep()

/ 908评论 / 6261阅读 / 0点赞

加入比较短时间的Sleep()一般对时效性影响不大,但能极大地降低CPU占用。

#include<conio.h>
#include<iostream>
#include<windows.h>
using namespace std;

int main()
{
	cout << "<< 按任意键继续... ";
	for (int i = 0; _kbhit() == 0;)	//等待按键
	{
		switch (i++)	//选择打印最后的一个字符,使之有动画效果
		{
		case 0:cout << "\b/"; break;
		case 1:cout << "\b-"; break;
		case 2:cout << "\b\\"; break;
		case 3:
		{
			cout << "\b|";
			i = 0;
		}break;
		}
		//Sleep(100);    //暂停100毫秒(1秒 = 1000毫秒)
	}
}
  1. RobertLAr说道:

    amoxicillin 500mg price: order amoxicillin online no prescription – cost of amoxicillin

  2. CEO quang huy说道:

    Greetings! Very useful advice within this post! It is the little changes that make the greatest changes. Many thanks for sharing!

  3. Your style is very unique in comparison to other folks I have read stuff from. Many thanks for posting when you have the opportunity, Guess I’ll just bookmark this web site.

  4. 78win说道:

    Pretty! This was a really wonderful post. Thank you for providing this info.

  5. Willard Tomasek说道:

    There is certainly a great deal to find out about this topic. I really like all the points you’ve made.

  6. Jamesjer说道:

    amoxicillin no prescription: buy amoxicillin canada – amoxicillin 500 mg capsule

  7. Jamesjer说道:

    doxycycline 300 mg price: doxycycline tablets buy online – cheap doxycycline 100mg capsule

  8. Jamesjer说道:

    buy cipro no rx: buy cipro online canada – cipro

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注