C++ 创建二维向量数组

C++ 创建二维向量数组,c++,vector,2d,C++,Vector,2d,我一直在尝试为游戏创建一个2D向量数组。这是我正在做的一个例子 struct TILE { int a; char b; bool c; }; TILE temp_tile; std::vector<TILE> temp_vec_tile; std::vector<std::vector<TILE>> tile; for (int x = 0; x < 10; x++) { for (int y = 0; y &l

我一直在尝试为游戏创建一个2D向量数组。这是我正在做的一个例子

struct TILE {
    int a;
    char b;
    bool c;
};

TILE temp_tile;

std::vector<TILE> temp_vec_tile;
std::vector<std::vector<TILE>> tile;


for (int x = 0; x < 10; x++) {
    for (int y = 0; y < 10; y++) {

    temp_tile.a = x;
    temp_tile.b = "a";
    temp_tile.c = false;;

    temp_vec_tile.push_back(temp_tile);
    }

    tile.push_back(temp_vec_tile);
}

// Why does this not work?
int x = tile[3][5].a;
struct-TILE{
INTA;
字符b;
布尔c;
};
瓷砖温度;
标准::向量温度向量瓷砖;
std::向量块;
对于(int x=0;x<10;x++){
对于(int y=0;y<10;y++){
温度a=x;
temp_tile.b=“a”;
temp_tile.c=假;;
临时向量。推回(临时向量);
}
瓷砖。向后推(临时瓷砖);
}
//为什么这不起作用?
int x=瓷砖[3][5].a;
注意:我不想为此使用Boost


谢谢

您没有每次都清除内部向量。您可能希望将内部向量声明放在第一个for循环中。

Brian R.Bondy已经解决了这个问题