去这里看看,有个人写了个小代码,能得到主要的的硬件信息: CPU,主板,内存,GPU,而你只需要那一行Number of CPU Cores = 4
https://github.com/tlewiscpp/SystemInfo代码使用:
#include <iostream>
#include <string>
#include <vector>
#include "stdafx.h"
#include "cpuinfodelegate.h"
#include "motherboardinfodelegate.h"
#include "raminfodelegate.h"
#include "gpuinfodelegate.h"
int main(int argc, char *argv[])
{
//First make a delegate object that handles the cases where the computer has multiple CPUs
CPUInfoDelegate *cpuInfo = new CPUInfoDelegate();
//Then extract the separate CPUs into a vector (of CPUInfo objects)
std::vector<CPUInfo> cpuInfoVector = cpuInfo->cpuInfoVector();
//Print out the number of CPUs, directory from the delegate object
std::cout << "This computer has " << cpuInfo->numberOfCPUInfoItems() << " CPU(s) installed" << std::endl;
//Iterate through all of the CPUs and print out the information for all of them
int CPUCount = 1;
for (std::vector<CPUInfo>::iterator iter = cpuInfoVector.begin(); iter != cpuInfoVector.end(); iter++) {
std::cout << "Information for CPU #" << CPUCount << ": " << std::endl;
std::cout << "CPU Name = " << iter->name() << std::endl;
std::cout << "CPU Manufacturer = " << iter->manufacturer() << std::endl;
std::cout << "Number of CPU Cores = " << iter->numberOfCores() << std::endl;
std::cout << "Current CPU Clock Speed = " << iter->currentClockSpeed() << std::endl;
std::cout << "CPU Architecture = " << iter->architecture() << std::endl;
std::cout << "CPU L2 Cache Size = " << iter->L2CacheSize() << std::endl;
std::cout << "CPU L3 Cache Size = " << iter->L3CacheSize() << std::endl;
std::cout << "Current CPU Temperature = " << iter->currentTemperature() << std::endl;
std::cout << std::endl;
CPUCount++;
}
delete cpuInfo;
MotherboardInfoDelegate *moboInfo = new MotherboardInfoDelegate();
std::vector<MotherboardInfo> moboInfoVector = moboInfo->motherboardInfoVector();
std::cout << "This computer has " << moboInfo->numberOfMotherboardInfoItems() << " motherboard(s) installed" << std::endl;
int motherboardCount = 1;
for (std::vector<MotherboardInfo>::const_iterator iter = moboInfoVector.begin(); iter != moboInfoVector.end(); iter++) {
std::cout << "Information for motherboard #" << motherboardCount << ": " << std::endl;
std::cout << "Motherboard Name = " << iter->name() << std::endl;
std::cout << "Motherboard Manufacturer = " << iter->manufacturer() << std::endl;
std::cout << "Motherboard Chipset = " << iter->chipset() << std::endl;
std::cout << "Motherboard Serial Number = " << iter->serialNumber() << std::endl;
std::cout << "Motherboard Version = " << iter->version() << std::endl;
std::cout << std::endl;
motherboardCount++;
}
delete moboInfo;
RAMInfoDelegate *ramInfo = new RAMInfoDelegate();
std::vector<RAMInfo> ramInfoVector = ramInfo->ramInfoVector();
std::cout << "This computer has " << ramInfo->numberOfRAMInfoItems() << " RAM stick(s) installed" << std::endl;
int ramCount = 1;
for (std::vector<RAMInfo>::const_iterator iter = ramInfoVector.begin(); iter != ramInfoVector.end(); iter++) {
std::cout << "Information for RAM stick #" << ramCount << ": " << std::endl;
std::cout << "RAM Name = " << iter->name() << std::endl;
std::cout << "RAM Manufacturer = " << iter->manufacturer() << std::endl;
std::cout << "RAM Capacity = " << iter->capacity() << std::endl;
std::cout << "RAM Serial Number = " << iter->serialNumber() << std::endl;
std::cout << "RAM Form Factor = " << iter->formFactor() << std::endl;
std::cout << "RAM Part Number = " << iter->partNumber() << std::endl;
std::cout << "RAM Memory Type = " << iter->memoryType() << std::endl;
std::cout << "RAM Clock Speed = " << iter->clockSpeed() << std::endl;
std::cout << std::endl;
ramCount++;
}
delete ramInfo;
GPUInfoDelegate *gpuInfo = new GPUInfoDelegate();
std::vector<GPUInfo> gpuInfoVector = gpuInfo->gpuInfoVector();
std::cout << "This computer has " << gpuInfo->numberOfGPUInfoItems() << " GPU(s) installed" << std::endl;
int gpuCount = 1;
for (std::vector<GPUInfo>::const_iterator iter = gpuInfoVector.begin(); iter != gpuInfoVector.end(); iter++) {
std::cout << "Information for GPU #" << gpuCount << ": " << std::endl;
std::cout << "GPU Name = " << iter->name() << std::endl;
std::cout << "GPU Manufacturer = " << iter->manufacturer() << std::endl;
std::cout << "GPU Adapter RAM = " << iter->adapterRAM() << std::endl;
std::cout << "GPU Refresh Rate = " << iter->refreshRate() << std::endl;
std::cout << "GPU Driver Version = " << iter->driverVersion() << std::endl;
std::cout << "GPU Video Architecture = " << iter->videoArchitecture() << std::endl;
std::cout << "GPU Video Mode Description = " << iter->videoModeDescription() << std::endl;
std::cout << std::endl;
gpuCount++;
}
std::cout << std::endl << "Press any button to continue...";
std::cin.get();
return 0;
}
输出信息如下:
This computer has 1 CPU(s) installed
Information for CPU #1:
CPU Name = Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
CPU Manufacturer = GenuineIntel
Number of CPU Cores = 4
Current CPU Clock Speed = 4008MHz
CPU Architecture = x86_64
CPU L2 Cache Size = 1024KB
CPU L3 Cache Size = 8192KB
Current CPU Temperature = unknown
This computer has 1 motherboard(s) installed
Information for motherboard #1:
Motherboard Name = Z170A XPOWER GAMING TITANIUM EDITION(MS-7968)
Motherboard Manufacturer = MSI
Motherboard Chipset = Intel(R) 100 Series/C230 Series Chipset
Motherboard Serial Number = G316062268
Motherboard Version = 3.0
This computer has 4 RAM stick(s) installed
Information for RAM stick #1:
RAM Name = ChannelA-DIMM0
RAM Manufacturer = 1315
RAM Capacity = 8589MB (8589934592 Bytes)
RAM Serial Number = 16171913
RAM Form Factor = DIMM
RAM Part Number = BLE8G4D26AFEA.16FAD
RAM Memory Type = Unknown
RAM Clock Speed = 2667MHz
Information for RAM stick #2:
RAM Name = ChannelA-DIMM1
RAM Manufacturer = 1315
RAM Capacity = 8589MB (8589934592 Bytes)
RAM Serial Number = 16231222
RAM Form Factor = DIMM
RAM Part Number = BLE8G4D26AFEA.16FAD
RAM Memory Type = Unknown
RAM Clock Speed = 2667MHz
Information for RAM stick #3:
RAM Name = ChannelB-DIMM0
RAM Manufacturer = 1315
RAM Capacity = 8589MB (8589934592 Bytes)
RAM Serial Number = 16114821
RAM Form Factor = DIMM
RAM Part Number = BLE8G4D26AFEA.16FAD
RAM Memory Type = Unknown
RAM Clock Speed = 2667MHz
Information for RAM stick #4:
RAM Name = ChannelB-DIMM1
RAM Manufacturer = 1315
RAM Capacity = 8589MB (8589934592 Bytes)
RAM Serial Number = 16171913
RAM Form Factor = DIMM
RAM Part Number = BLE8G4D26AFEA.16FAD
RAM Memory Type = Unknown
RAM Clock Speed = 2667MHz
This computer has 1 GPU(s) installed
Information for GPU #1:
GPU Name = NVIDIA GeForce GTX 980 Ti
GPU Manufacturer = NVIDIA
GPU Adapter RAM = 4293MB (4293918720 Bytes)
GPU Refresh Rate = 144MHz
GPU Driver Version = 10.18.13.6881
GPU Video Architecture = Unknown
GPU Video Mode Description = 1920 x 1080 x 4294967296 colors
Press any button to continue...
【 在 hgoldfish 的大作中提到: 】
: 你和上面 libgcc 说的都是返回线程数。不是物理核心数。
:
--
FROM 82.19.154.*