Iterator For Multidimensional Vector
I'm having trouble wrapping my head around this idea/concept.
I know how an iterator works for a single dimension vector. You have the reverse iterator and the forward iterator. I would assume that you can have iterators for multidimensional vectors as well. However if you wanted to print the contents of the multidimensional vector, would you have to have an iterator for each dimension or could you use a single iterator to navigate though the vector in a row-by-row fashion?
Re: Iterator For Multidimensional Vector
Having never tried it with iterators.. I'm unsure.. I assume its the same though..
Code:
vector<vector<int>> testVector;
vector<vector<int>>::iterator it;
it = testVector.begin();
++it;
etc..
Vectors are random access anyway.. so you can just as easily do this:
Code:
vector<vector<int>> testVector;
cout << testVector[x][y];
chem
Re: Iterator For Multidimensional Vector
I asked around on the CProgramming forums and apparently you can have something like this (assuming that I have a multidimensional vector set up):
Code:
vector<int>::iterator forwardDim1;
vector< vector<int> >::iterator forwardDim2;
You'd need an iterator for each dimension in the vector. I was just trying to think of another way to access the elements of the vector besides for the for loop method.
Re: Iterator For Multidimensional Vector
Yeah.. that makes sense. Strange that I completely missed that second part when I replied! Stupid brain of mine!
chem