以下是一个根据 CPU 个数动态生成大小为3的二维数组的 C++ 实现方式:

#include <iostream>
#include <vector>
#include <thread>

int main() {
    int cpuCount = std::thread::hardware_concurrency();  // 获取 CPU 个数
    std::vector<std::vector<int>> array(cpuCount, std::vector<int>(3));  // 动态生成二维数组

    // 输出二维数组
    for (int i = 0; i < cpuCount; ++i) {
        for (int j = 0; j < 3; ++j) {
            std::cout << array[i][j] << " ";
        }
        std::cout << std::endl;
    }

    return 0;
}

这里使用了std::vector来动态生成二维数组,其中cpuCount表示 CPU 的个数,array是一个大小为cpuCountvector,每个元素都是一个大小为3的vector。你可以根据实际需求修改数组的数据类型和大小


原文地址: https://www.cveoy.top/t/topic/iNNA 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录