I'm trying to figure out how to resize a vector of vectors based upon the user's input. I'm making a method called setGrid which should take in the # of rows and columns and then generate a chessboard based upon that. I can resize outer vector no problem but how would I resize the inner vectors too? This is what I have right now so you can see where my head is at.
1 2 3 4 5 6 7 8
grid_ = vector<vector<int>>(9,vector<int>(9));
void setGrid (int new_i, int new_j)
//trying to figure out how to resize the grid based on input from user
How many rows?
How many columns>
Vec has 4 row.
Row 0 has 2 columns.
Row 1 has 2 columns.
Row 2 has 2 columns.
Row 3 has 2 columns.
Process returned 0 (0x0) execution time : 1.981 s
Press any key to continue.
Sorry, it was just initialized randomly as 9x9 so I could test it and make sure it was constructed correctly. Your code makes sense and is incredibly helpful and I can see where you're going but what is "auto &it : vec"? When I try putting that in my code to try and wrap my head around it, I get errors saying "it" needs to be initialized. What exactly is "it", and what does the "auto" function do?
auto is a variable type that gets the variable type automatically and it is just a variable name like i but I chose it because it is short for iterator the & is for the reference because I am iterating based on the reference not the value
There are other ways you can iterate but I did it the c++11 method by doing
iterator : thingToBeIterated
Another method ( not tested but should be similar )
for( std::vector<std::vector<int> >::iterator it = vec.begin(); it != vec.end(); ++it )
Go to the toolbar on the top and there should be either a compiler tab or a settings tab with a compiler option under that. Once there either check the flag that says c++11 or under the other settings put this
-std=c++11 if it is GCC as a compiler that is.
MSVC++ allows for those template declarations even for C++03, ...
Unless you're unlucky enough to work on a legacy codebase which is still using a pre-2005 version of Visual Studio... :-(
Versions of Visual Studio prior to Visual Studio 2005 required that whitespace be inserted between template parameter lists when nested template instances were declared. The following syntax is now allowed in Visual Studio 2005 ...