Riko Kurahashi
Riko Kurahashi

Reputation: 61

Setting up a grid with vectors in C++?

#include <iostream>
#include <vector>

using namespace std;

void printGrid(const vector <vector <int> > &grid){
for (int row = 0; row < grid.size(); row++)
{
    for (int column = 0; column < grid.at(row).size(); column++)
    {
        if (grid.at(row).at(column) == WALL)
        {
            printWall();
        }
        else if (grid.at(row).at(column) == COLOR)
        {
            printColor();
        }
        else
        {
            printEmpty();
        }
    }
}
}

For this function, I am to take in an input for grid and produce a grid with it like

xxxSxxxxxxxxxxxxxxx
x                 x
xxxxxxx xxxxxxxxxxx
x                 x
xxxxxxxxxxxxxxGxxxx

where S is the starting point and G is the ending point.

However, for my function, it output everything on to one line instead of making a nice grid. How can I resolve this? Thank you.

Edit:

const int EMPTY = 1;
const int WALL = 2;
const int COLOR = 3;
const int TO_BE_COLORED = 4;

the variables just give a color by using a different file.

Upvotes: 0

Views: 1969

Answers (1)

Oswald
Oswald

Reputation: 31647

Print a '\n' after the last column of a row has been printed.

Upvotes: 1

Related Questions