永发信息网

C++ 怎么实现获取当前PC 硬盘 内存的大小以及已使用大小,加上CPU使用率

答案:4  悬赏:30  手机版
解决时间 2021-04-07 02:50
C++ 怎么实现获取当前PC 硬盘 内存的大小以及已使用大小,加上CPU使用率
最佳答案
可以通过编程实现,源代码如下:
// Sample output:
// There is 51 percent of memory in use.
// There are 2029968 total KB of physical memory.
// There are 987388 free KB of physical memory.
// There are 3884620 total KB of paging file.
// There are 2799776 free KB of paging file.
// There are 2097024 total KB of virtual memory.
// There are 2084876 free KB of virtual memory.
// There are 0 free KB of extended memory.

#include
#include
#include

// Use to convert bytes to KB
#define DIV 1024

// Specify the width of the field in which to print the numbers.
// The asterisk in the format specifier "%*I64d" takes an integer
// argument and uses it to pad and right justify the number.
#define WIDTH 7

void _tmain()
{
MEMORYSTATUSEX statex;

statex.dwLength = sizeof (statex);

GlobalMemoryStatusEx (&statex);

_tprintf (TEXT("There is %*ld percent of memory in use.\n"),
WIDTH, statex.dwMemoryLoad);
_tprintf (TEXT("There are %*I64d total KB of physical memory.\n"),
WIDTH, statex.ullTotalPhys/DIV);
_tprintf (TEXT("There are %*I64d free KB of physical memory.\n"),
WIDTH, statex.ullAvailPhys/DIV);
_tprintf (TEXT("There are %*I64d total KB of paging file.\n"),
WIDTH, statex.ullTotalPageFile/DIV);
_tprintf (TEXT("There are %*I64d free KB of paging file.\n"),
WIDTH, statex.ullAvailPageFile/DIV);
_tprintf (TEXT("There are %*I64d total KB of virtual memory.\n"),
WIDTH, statex.ullTotalVirtual/DIV);
_tprintf (TEXT("There are %*I64d free KB of virtual memory.\n"),
WIDTH, statex.ullAvailVirtual/DIV);

// Show the amount of extended memory available.

_tprintf (TEXT("There are %*I64d free KB of extended memory.\n"),
WIDTH, statex.ullAvailExtendedVirtual/DIV);
}

运行后结果就能获取当前PC的硬盘大小、已使用大小和CPU的使用率。追问尼玛回答的太及时了吧,才那么短短五六年你就抢着回答了
全部回答
上csdn里一大把。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
我黄山的今年文科高考510分想复读到哪个学校
全国各地都有哪些地方有密室逃脱
风景美丽有意境的诗句,优美的、很有意境的句
白色诅咒的旋律那不恐怖片子最后到底怎么回事
CF穿越火线中第一个英雄级人物是谁?
“The Voice of China”to be an unexpected
万裕路我想知道这个在什么地方
62减4等于23动一根火柴
武汉636路公交属于哪个公司,电话时多少?
水样测定氨氮比凯氏氮高,会是什么原因
为什么我的TP-LINK路由器设置了psk密码后,手
大侠们请问下建筑设计中,地下室设备用房有什
封闭式学校哪里好
大宋提刑官宋慈有没有孩子
流水行船问题:一位少年短跑选手,顺风跑90米
推荐资讯
三颗针泡酒有何功效与作用
以混血种人占多数的地区是?
为什么开机屏幕黑的显示模拟两个字
惠州2天游,想去西湖,红花湖,奥地利小镇,
黄瓜拌糖吃了会怎么样
我像哪个明星啊各位
预祝比赛获奖祝福语,对一个喜爱篮球的男生的
单选题选出标点符号使用正确的一句,并指出其
孩子的抚养权归男方,女方强行带走孩子,女方
为什么我家屋顶上经常出现一起鸟,晚上还在屋
皈依三宝后破戒了会不会很严重?
处女座和双子座
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?