Alex Rivera | Logout

How do you copy the contents of an array to a std::vector in C++ without looping?

Asked 2008-11-03T17:03:46.273
162

I have an array of values that is passed to my function from a different part of the program that I need to store for later processing. Since I don't know how many times my function will be called before it is time to process the data, I need a dynamic storage structure, so I chose a std::vector. I don't want to have to do the standard loop to push_back all the values individually, it would be nice if I could just copy it all using something similar to memcpy.

Edit
Report

1 Answer

12

std::copy is what you're looking for.

answered 2008-11-03T17:07:34.283

Your Answer