Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在c+中输出多维数组内容的for循环的结构是什么+;_C++ - Fatal编程技术网

C++ 在c+中输出多维数组内容的for循环的结构是什么+;

C++ 在c+中输出多维数组内容的for循环的结构是什么+;,c++,C++,我需要看一个如何输出多维数组的示例 string** row = new string*[level]; for(int i = 0; i < level; ++i) { row[i] = new string[level]; } // outputting: int x; // filled with some value int y; // filled with some value string**row=新字符串*[level]; 对于(int i=0;i >

我需要看一个如何输出多维数组的示例

string** row = new string*[level];
for(int i = 0; i < level; ++i) {
      row[i] = new string[level];
}

// outputting:

int x; // filled with some value

int y; // filled with some value
string**row=新字符串*[level];
对于(int i=0;i

<>我如何打印<代码>行[y] [x] < /> >通过<代码> y>代码>然后代码> x< /代码>

首先,您应该考虑使用STD::vector,而不是手动动态分配,因为您使用C++:

std::vector<std::vector<std::string>> rows(level);
并以这种方式初始化它:

for (std::vector<std::string>& row_vec : rows)
{
    row_vec.resize(level);
}
for(std::vector和row\u vec:rows)
{
行向量调整大小(级别);
}
要对其进行迭代,只需使用嵌套for循环:

for (uint32_t x(0); x < level; ++x)
{
    for (uint32_t y(0); y < level; ++y)
    {
        std::cout << "rows[" << x << "][" << y << "] = " << rows[x][y] << std::endl;
    }
}
(uint32_t x(0);x { 对于(uint32_t y(0);ystd::cout嵌套
用于
循环,一个用于
x
,一个用于
y
。还可以将值推回向量中的特定点
for (uint32_t x(0); x < level; ++x)
{
    for (uint32_t y(0); y < level; ++y)
    {
        std::cout << "rows[" << x << "][" << y << "] = " << rows[x][y] << std::endl;
    }
}