2D vector display

hi. currently trying to make a battleship type game, and have created a vector using user input of 'x' width and 'y' height, and need to find a way to display this vector as a grid and have each square be a cell that can be altered using the co-ordinates of the square.

this is the set up currently being used for the vector:

class Board
{
public:
static int displayBoard()
{
int x, y;
std::cout << "input width:";
std::cin >> x;
std::cout << "\n input height:";
std::cin >> y;
std::vector <int> BoardSize (x, y);


return 0;
}

};

if someone could help out, or reccomend a better way alltogether to do this that would be fantastic :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <vector>
 
int main()
{
    std::vector<std::vector<size_t>> grid;
 
    size_t width, height;
 
    std::cout << "input width:";
    std::cin >> width;
    std::cout << "\n input height:";
    std::cin >> height;
 
    grid.resize( height, std::vector<size_t>( width ) );
    
    std::cout << "Grid: " << grid.size() << " x " << grid[0].size() << std::endl;
}
Topic archived. No new replies allowed.