I'm migrating from C language to C ++, and I want to stop using traditional C language media as the vector of it.
Is it possible to use std::array
to insert elements dynamically as in std::vector
?
I'm migrating from C language to C ++, and I want to stop using traditional C language media as the vector of it.
Is it possible to use std::array
to insert elements dynamically as in std::vector
?
Congratulations, you're doing the right thing. C is C, C ++ is C ++.
Essentially it can not, this is a fixed size structure. The std:array
is identical to the array of C, which does not allow you to insert new elements in it dynamically or statically. So if you want a replacement for the array , it's it, just do not demand from it what the C engine does not provide. If you want to dynamically manipulate it, it's very simple, use std:vector
. Depending on the case you should even use a std::list
.
Related: Difference between std :: list, std :: vector and std :: array