在构造函数中初始化2D数组的值时遇到问题。我正在创建一个Tic-Tac-Toe游戏。我需要初始化2D数组中的值,以便将值显示在板上。我不确定这样做的方式。
I used a nested for loop to initialize values but it didn't work.
class TicTacToe
{
private:
char matrix[3][3];
public:
TicTacToe();
TicTacToe(char matrix[3][3]);
TicTacToe::TicTacToe(char matrix[3][3])
{
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cout << matrix[i][j] << " ";
}
cout << endl;
}
}
I expect the values from the array to be displayed on the board.