Let's say I have a 2D vector of strings. I'm trying to implement an iterator that moves through the rows of the table. When I'm in each row, what's the format for getting the iterator to return the first element of that row, a string?
One of the beautiful things of vectors is that they don't "need" iterators...
You can simply use two integers ("row" and "column" for easy) and use them to walk through the 2D vector. You enter the next row by doing row++ and you go to the next column by doing column++. You access an element by using my2DVec[row][column].
If you still want an iterator, just use the built-in one and use "vector<string>" as type. Dereferencing will give a pointer to that vector ("row"). Then put a normal iterator on that 1D vector. Dereferencing that one will give the current string.
Wouldn't I need vector<vector<string> > it; for the table iterator that moves through rows? I'm trying to move through the rows of a 2D vector and compare each row's first column (a string) with another string, but I'm having trouble figuring out how to do that.
it depends in what order you wish to access the elements, but you need to iterate through two seperate things. You have a vector of vectors, and the vectors contained by that vector are vectors of strings, so iterating through the first vector(of vectors) iterates through the columns, and iterating through the second vector(of strings) iterates through the rows (or vice versa, depending on how you choose to view the layout of the data.