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

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -