I have been following a tutorial on how to output two-dimensional vector with C++ and arrived at the following code:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector < vector < int > > test { { 1, 2, 3,
4, 5, 6,
7, 8, 9 } };
for( unsigned int i = 0; i < test.size(); i++ )
{
for( unsigned int j = 0; j < test[i].size(); j++ )
{
cout << test[i][j] << " ";
}
cout << endl;
}
}
which produces the following output:
1 2 3 4 5 6 7 8 9
As you can see my results do not look exactly as intended; i want to be able to output the vector into a two-dimensional grid-like space. As far as I can tell my code follows the example, but the cout << endl;
after the inner for loop is not breaking the vector into rows like it should be. Can someone please explain to me what I am doing wrong, or show me the proper method to output a two-dimensional vector into a grid-like pattern?