I am trying to add a certain value in loop to a given position of a certain vector. For example:
- the value is 11 and hence
local_index = 11 - The vector of position I have in input is
neigh = {5,7} - The starting vector is
Col={0,1,2,3,4,5,6,7,8,9,10}
I want to have as output Col={0,1,2,3,4,5,11,6,7,11,8,9,10}. This is my first try:
vector<long> neigh = {5,7};
long local_index = 11;
auto pos_col = Col.begin();
for (const auto& elem: neigh) {
Col.insert(pos_col+elem,local_index);
I keep getting for the second value of neigh a segmentation fault. So my questions are:
- Is this because the insert return a pointer that cannot be re-assigned?
- If the answer to the first question is yes, how can I achieve my goal?