Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

vector::insert

std::vector<int> vecOfNums{ 1, 4, 5, 11, -3, -10, 15 };

// Inserting a single element:
auto itPos = vecOfNums.begin() + 2; // Iterator to wanted postion
vecOfNums.insert(itPos, 77); // Insert new Element => 1, 4, 77, 5, ..
    
// Inserting part or full other vector
std::vector<int> otherVec{ 33, 33, 55 };
vecOfNums.insert(vecOfNums.begin() + 1, otherVec.begin(), otherVec.begin() + 2); // 1, 33, 33, 4, ..
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
8+9 =