I\'m trying to work with vectors of vectors of ints for a sudoku puzzle solver I\'m writing.
Question 1:
If I\'m going to access a my 2d vec
Q1: Yes, that is the correct way to handle it. However, notice that nested vectors are a rather inefficient way to implement a 2D array. One vector and calculating indices by x + y * width
is usually a better option.
Q2A: Calculating grid[i][j] + " "
does not concatenate two strings (because the left hand side is int, not a string) but instead adds the numeric value to a pointer (the memory address of the first character of the string " "). Use cout << grid[i][j] << " "
instead.
Q2B: You are passing the array by value (it gets copied) for readAPuzzle
. The the function reads into its local copy, which gets destroyed when the function returns. Pass by reference instead (this avoids making a copy and uses the original instead):
void readAPuzzle(array2d_t& grid)