Please take a look at the MRE below:
#include <iostream>
#include <vector>
#include <iterator>
void display(const std::vector<std::string> &v){
for(int i = 0; i < v.size(); i++){
std::cout << v[i] << " ";
}
std::cout << std::endl;
}
int main(){
std::vector<std::string> vect1;
std::vector<std::string>::iterator i1 = vect1.begin();
vect1.push_back("Test");
display(vect1);
std::cout << *i1 << std::endl;
vect1.insert(i1, "Apple");
std::cout << vect1.size() << std::endl;
display(vect1);
return 0;
}
When I try to add a new element to vect1
with use of insert
function the vector content remains the same (according to display
function output). Is there anything I'm missing here?