Replace an element into a specific position of a vector

后端 未结 3 1608
臣服心动
臣服心动 2020-12-07 13:00

I want to replace an element into a specific position of a vector, can I just use an assignment:

// vec1 and 2 have the same length & filled in somehow
v         


        
3条回答
  •  既然无缘
    2020-12-07 13:29

    See an example here: http://www.cplusplus.com/reference/stl/vector/insert/ eg.:

    
    
    ...
    vector::iterator iterator1;
    
      iterator1= vec1.begin();
      vec1.insert ( iterator1+i , vec2[i] );
    
    // This means that at position "i" from the beginning it will insert the value from vec2 from position i
    
    

    Your first approach was replacing the values from vec1[i] with the values from vec2[i]

提交回复
热议问题