永发信息网

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

答案:4  悬赏:30  手机版
解决时间 2021-04-07 02:50
  • 提问者网友:容嬷嬷拿针来
  • 2021-04-06 07:29
C++ 怎么实现获取当前PC 硬盘 内存的大小以及已使用大小,加上CPU使用率
最佳答案
  • 五星知识达人网友:患得患失的劫
  • 2021-04-06 08:43
可以通过编程实现,源代码如下:
// 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的使用率。追问尼玛回答的太及时了吧,才那么短短五六年你就抢着回答了
全部回答
  • 1楼网友:骨子里都是戏
  • 2021-04-06 10:45
上csdn里一大把。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯