C++常用

C++常用

控制台输出命名空间

#include <windows.h>
#include <iostream>
#include <stdio.h>
using namespace std
//控制台打印字符串
char cha[] = "世界你好!";
cout << "字符串地址=:" << &cha<<endl;
#pragma comment(lib,"testDLL.lib")
//NMCHAR https://learn.microsoft.com/zh-cn/windows/win32/controls/subclassing-overview
//常规控件参考 https://learn.microsoft.com/zh-cn/windows/win32/controls/common-control-reference 
#pragma warning(disable:4996)**加粗样式**

毫秒级时间计算

#include <stdio.h>
#include <windows.h>
#include <time.h> //time_t time()  clock_t clock()
#include <Mmsystem.h>             //timeGetTime()
#pragma comment(lib, "Winmm.lib")   //timeGetTime()
int main()
{
	//用time()来计时  秒
	time_t timeBegin, timeEnd;
	timeBegin = time(NULL);
	Sleep(1000);
	timeEnd = time(NULL);
	printf("%d\n", timeEnd - timeBegin);
	//用clock()来计时  毫秒
	clock_t  clockBegin, clockEnd;
	clockBegin = clock();
	Sleep(800);
	clockEnd = clock();
	printf("%d\n", clockEnd - clockBegin);
	//用timeGetTime()来计时  毫秒
	DWORD  dwBegin, dwEnd;
	dwBegin = timeGetTime();
	Sleep(800);
	dwEnd = timeGetTime();
	printf("%d\n", dwEnd - dwBegin);
	//用GetTickCount()来计时  毫秒
	DWORD  dwGTCBegin, dwGTCEnd;
	dwGTCBegin = GetTickCount();
	Sleep(806);
	dwGTCEnd = GetTickCount();
	printf("%d\n", dwGTCEnd - dwGTCBegin);
	//用QueryPerformanceCounter()来计时  微秒
	LARGE_INTEGER  large_interger;
	double dff;
	__int64  c1, c2;
	QueryPerformanceFrequency(&large_interger);
	dff = large_interger.QuadPart;
	QueryPerformanceCounter(&large_interger);
	c1 = large_interger.QuadPart;
	Sleep(800);
	QueryPerformanceCounter(&large_interger);
	c2 = large_interger.QuadPart;
	printf("本机高精度计时器频率%lf\n", dff);
	printf("第一次计时器值%I64d 第二次计时器值%I64d 计时器差%I64d\n", c1, c2, c2 - c1);
	printf("计时%lf毫秒\n", (c2 - c1) * 1000 / dff);
	printf("By MoreWindows\n");
	return 0;

	//LARGE_INTEGER start, end;
	//LARGE_INTEGER pers;
	//QueryPerformanceFrequency(&pers);
	//double dff = pers.QuadPart;
	//QueryPerformanceCounter(&start);

	//Sleep(2805);
	//QueryPerformanceCounter(&end);
	//hw.Format("%I64f", (end.QuadPart - start.QuadPart) * 1000 / dff);
	//SetDlgItemText(EDIT1, hw);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

C+V代码搬运工

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值