c++ - Adding to middle of std::vector -
is there way add values middle of vector
in c++? have:
vector <string> a; // gets filled "abcd", "wertyu", "dvcea", "eafdefef", "aeefr", etc
and want break 1 of strings , put of pieces vector
. how that? strings break can anywhere, index = 0, somewhere in middle, or index = a.size() - 1
.
you can insert vector
@ position i
writing
v.insert(v.begin() + i, valuetoinsert);
however, isn't efficient; runs in time proportional number of elements after element being inserted. if you're planning on splitting strings , adding them in, better off using std::list
, supports o(1) insertion , deletion everywhere.
Comments
Post a Comment