Results 1 to 4 of 4

Thread: Iterator For Multidimensional Vector

  1. #1

    Thread Starter
    Hyperactive Member GamerMax5's Avatar
    Join Date
    Nov 2004
    Location
    United States
    Posts
    388

    Question 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?

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    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

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3

    Thread Starter
    Hyperactive Member GamerMax5's Avatar
    Join Date
    Nov 2004
    Location
    United States
    Posts
    388

    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.

  4. #4
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    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

    Visual Studio 6, Visual Studio.NET 2005, MASM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width