A direct way to initialize a vector from an array is as follows:
int sizeArr; int * array = getArray(sizeArr); std::vector<int> vec(array, array+sizeArr);
Here I get an array from a function that allocates space in memory and sets sizeArr by reference. {start edit} Unfortunately, the function is not written by me, and I need to deal with an array of C styles, and then somehow convert it to a vector. (If possible, effective). {end edit}
When I initialize vec , I obviously allocate space for it separately. If I no longer intend to use the data with array , is it possible to somehow "move" the data indicated by the array symbol to the vec vector and not allocate any space for it separately?
c ++ arrays vector
aatish
source share