i'm having some trouble on initializing an empty array ,or so i call it, in a class. basically i want to fill a 2d array with 0.
here's my code:
Board.cpp
#include "Board.h"
#include <string>
#include <iostream>
#include "Player.h"
using namespace std;
Board::Board()
: _board{ { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } }
{
}
void Board::drawBoard()
{
for (int i = 0; i < 4; i++){
for (int j = 0; j < 4; j++){
if (i == 0 && j == 0){
cout << " ";
}
else if (i == 0){
cout << " " << j << " ";
}
else if (j == 0){
cout << i;
}
else {
if (_board[i][j] == 0)
cout << "| " << "|";
else
cout << "|" << _board[i][j] << "|";
}
}
cout << endl;
}
}
void Board::playerInput(char input)
{
}
here is Board.h:
#pragma once
#include <string>
#include <iostream>
class Board
{
public:
Board();
void drawBoard();
void playerInput(char input);
private:
char _board[3][3];
char _input;
};
is that a right way to initialize an array? i read some articles but it just confuses me more. i'm sorry if i sound stupid. but i need your help. thank you.