制作数组堆栈和向量的二维数组



我正在尝试使用STL堆栈来保存我的变量。我有两个变量声明为vector array[8][8]和int array[8][8]。我该如何声明堆栈?它会像一样吗

stack<vector<int>> array
stack<int>array// not really sure how to use stacks at this point.

编辑:这就是我想做的:

class example
{
private:
vector<int> cells[8][8]//2d array of vectors, one vector for each of the 64 cells
int table[8][8]; //table of 64 elements
//here is what I want to implement
stack<int,vector<int>> cells_stack;// a stack of vectors so that I can backtrack on the vectors if inputs on the table are incorrect
stack<int> table_stack;//stack of array so that I can backtrack;
};

如果我理解正确,您希望将cellstable的内容存储在堆栈中。如果这是正确的,那么您要做的就是将堆栈声明为与要存储的对象完全相同。由于cells是一个类型为vector<int>的8x8数组,因此cells_stack应该包含该数组。例如:

stack<vector<int>[8][8]> cells_stack; 

table_stack也是如此,它应该包含类型为int:的8x8阵列

stack<int[8][8]> table_stack;