cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Adding objects to the front of a vector
Adding objects to the front of a vector
Sep 6, 2010 at 1:09am UTC
pabloist
(132)
Is there an easy way to add objects to the front of a vector? I know that myvector.push_back(myobject) will add myobject to the back of myvector. Is there a similar function that will add it to the front?
Sep 6, 2010 at 1:13am UTC
Disch
(13742)
You can use insert.... but.... adding to the front of a vector is very expensive because vector has to move ALL the data over to add additional space.
If you need to add to the front and back, consider using a deque instead.
Sep 6, 2010 at 4:47am UTC
pabloist
(132)
Thanks, I've never really used any of the STL containers besides the vector so far. I'll look into deque.
Topic archived. No new replies allowed.