vectors and vector iterators

Vectors are new to me and I am having a hard time finding documentation on how to use them. I am also wondering how to use their iterators.

So my goal is to create a vector (essentially a dynamic array) of references/pointers of type Account. I then need to have insert/remove and find functions (presumably using an iterator) for the vector.

Any ideas?
Use std::vector<Account *> :)

There's documentation for it. The methods you're looking for is push_back(), remove(), and to find something you'll need to write your own function for that.

Here's documentation on iterator. Gotta be careful using iterator with vector, whenever it resizes any pointers you have to that vector (ie iterators) could become invalidated and you'll need to reset them.
Yeah, I was playing around with std::vector<Account*> and that seems to hold the pointers to Account just fine but then how do I implement random access. I am getting stuck with this-> or * or & and how I can implement things like find.
Would it look like

for(int acc = 0; acc != accounts.end(); acc++)
  if(acounts[acc].getName == "Bob")

I am not sure if I need an iterator or if I have to use accounts* or accounts& or accounts->.

I don't see remove(). Did you mean erase()?
Ah yea I meant erase(). Not sure why I said remove().
Topic archived. No new replies allowed.