计时器与多线程

本文详细介绍了如何在编程中使用计时器与多线程技术,结合具体的gotoxy函数用法,阐述了如何在屏幕上动态定位输出,讨论了在多线程环境下光标移动的实现和挑战。
摘要由CSDN通过智能技术生成
//复习三种容器
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <numeric>
#include <string>
using namespace std;
struct S
{
   
	string name;
	double score;	
	bool operator==(S s)
	{
   
		return score<s.score;//返回小的数,效果是自动排序(从小到大)
	}
};
class test
{
   
private:
	vector<S>a1;	
	vector<S>::iterator p1;	
	list<S>a2;	
	list<S>::iterator p2;	
	map<int,S>a3;	
	map<int,S>::iterator p3;	
public:
	test()
	{
   
		S t;//结构体
		t.name="111";t.score=11;
			a1.push_back(t);a2.push_back(t);
			a3.insert(pair<int,S>(1,t));//第一个是数据类型,第二个是结构体,括号内的是插入的数据
		t.name="222";t.score=22;
			a1.push_back(t);a2.push_back(t);
			a3.insert(pair<int,S>(2,t));
		t.name="333";t.score=33;
			a1.push_back(t);a2.push_back(t);
			a3.insert(pair<int,S>(3,t));
		t.name="444";t.score=44;
			a1.push_back(t);a2.push_back(t);
			a3.insert(pair<int,S>(4,t));
		t.name="555";t.score=55;
			a1.push_back(t);a2.push_back(t);
			a3.insert(pair<int,S>(5,t));
		//
	}
	void Find1(double d)
	{
   
		S temp;
		temp.score=d;
		p1=a1.begin();
		while(true)
		{
   
			p1=find(p1,a1.end(),temp);//第一个参数是p的起始地址,第二个参数是p的结束地址,第三个参数是需要查找的值
			if(p1!=a1.end())
			{
   
				cout<<p1->name<<"-"<<p1->score<<endl;
				++p1;
			}
			else break;
		}
	}
	void Find2(double d)
	{
   
		S temp;
		temp.score=d;
		p2=a2.begin();
		while(true)
		{
   
			p2=find(p2,a2.end(),temp);
			if(p2!=a2.end())
			{
   
				cout<<p2->name<<"-"<<p2->score<<endl;
				++p2;
			}
			else break;
		}
	}
	void Find3(int m)
	{
   
		p3=a3.find(m);
		if(p3!=a3.end())
		{
   
			cout<<p3->first<<"-"<<p3->second.name
							<<"-"<<p3->second.score<<endl;			
		}
		else	cout<<"no person!"<<endl;
	}
};
int main()
{
   
	test t;
	t.Find3(6);
	return 0;	
}
//gotoxy函数
#include <windows.h>
#include <iostream>
using namespace std;

//光标移动到指定坐标处
void gotoxy(int x,int y)
{
   
	HANDLE h;//句柄,对象的索引
	COORD c;//结构体,坐标值
	c.X=x;
	c.Y=y;
	h=GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(h,c);
}
int main()
{
   
	gotoxy(5,5);
	cout<<"hello!";
	return 0;
}

gotoxy(x, y) 将光标移动到指定列坐标 x 和行坐标 y。设置光标到文本屏幕的指定位置,其中参数 x,y 为文本屏幕的坐标。gotoxy(0,0)将光标移动到屏幕左上角。

//光标移动到指定坐标处
void gotoxy(int x,int y)
{
   
	HANDLE h;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值