Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. vect.push_back("Hello");
  2. vect.push_back("Hi");
  3. vect.push_back("Rasmi");
  4. for(vect<string>::iterator it = vect.begin(); it != vect.end(); ++it)
  5. {
  6. if(*it == "Rasmi") // If it encounters "Rasmi"
  7. {
  8. //it--;
  9. int index = it - vect.begin ();
  10. vect.insert(vect.begin()+2, "Hi");
  11. it = vect.begin () + index;
  12. }
  13. cout << *it;
  14. }
  15.  
  16. Hello->Hi->Rasmi... The execution becomes successful.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement