7
I’m migrating from C to C++ language, and I want to stop using traditional C language means, like the C vector.
It is possible using the std::array
insert elements dynamically as in std::vector
?
7
I’m migrating from C to C++ language, and I want to stop using traditional C language means, like the C vector.
It is possible using the std::array
insert elements dynamically as in std::vector
?
6
Congratulations, you’re doing the right thing. C is C, C++ is C++.
Essentially it cannot, this is a fixed size structure. The std:array
is identical to the array of C, which does not allow inserting new elements in it dynamically or statically. So a replacement for the array, is it, just don’t demand from it what the C mechanism doesn’t provide. If you want to manipulate it dynamically, it’s very simple, use a std:vector
. Depending on the case you should even use one std::list
or other structure.
Related: Difference between Std::list, Std::vector and Std:array
Browser other questions tagged c c++ array stl
You are not signed in. Login or sign up in order to post.