Trying to store lots of values in a vector?

This is a discussion on Trying to store lots of values in a vector? within the C++ Programming forums, part of the General Programming Boards category; Hey guys
I need to store lots of values in a dynamic-sized array, so I opted for vectors. I've had ...

Trying to store lots of values in a vector?

Hey guys

I need to store lots of values in a dynamic-sized array, so I opted for vectors. I've had some problems in the past trying to do something similar so I'm asking for someone to please give me a code sample of something basic of what I want to archieve. I need to store the following values:

And maybe some more. I don't have the code I've been using right now (that's why I'm asking to please make me some code sample I can try later) but if I can recall correctly, I had problems with getting the vector size... if I tried to get it in main() where I created a new record (vector.push_back() ), vector.size() returned the right value (1), but if I tried to get it from another function, vector.size() would return 6!... it's confusing and it's been driving me nuts this week :/...

If anybody could lend me a hand here I'd be really glad. I'll try to post the code I'm using in a few hours when I wake up and go to work :P

You just need to link the sections of the list together. You may not even need a doubly linked list depending on what you're using this for. If you really need a vector though, just throw everything into a struct and use the struct as your vector type.

You just need to link the sections of the list together. You may not even need a doubly linked list depending on what you're using this for. If you really need a vector though, just throw everything into a struct and use the struct as your vector type.

I don't see how a hand-coded linked list is in any way preferable to a std::list, or even a std::vector, depending on the application.

std::vector::size returns the number of items in the vector. Note that the item at index 0 in the vector counts as 1 item.

A hand coded doubly linked list is not going to benefit you much. There are plenty of STL container types designed to do just what you need.

Each container has its pros and cons and each was designed to perform a certain task. Make sure you understand the container and its purpose prior to using it. For what you want to do a vector seems ok - if you do not need to insert items in the vector. If you need to do a lot of inserting then a vector is not the best container for the job.

Check your compiler help file as it will tell you all about the different container types.