fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4.  
  5. void printall(std::vector <int> &v)
  6. {
  7. for (unsigned int i=0; i<v.size(); i++)
  8. {
  9. std::cout << "test.at(" << i << ")= " << v.at(i) << std::endl;
  10. }
  11. }
  12.  
  13.  
  14. int main()
  15. {
  16. std::vector <int> test (6);
  17.  
  18. for (int i=0; i<6; i++)
  19. {
  20. test[i]=i;
  21. }
  22.  
  23. std::vector <int>::iterator insertionPoint;
  24.  
  25. printall(test);
  26. std::cout << std::endl;
  27.  
  28. test.push_back(57);
  29.  
  30.  
  31. printall(test);
  32. std::cout << std::endl;
  33.  
  34. insertionPoint = test.begin() + 1;
  35. test.insert (insertionPoint, 12);
  36.  
  37.  
  38. printall(test);
  39. std::cout << std::endl;
  40.  
  41.  
  42. char response;
  43. std::cin >> response;
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0s 2992KB
stdin
Standard input is empty
stdout
test.at(0)= 0
test.at(1)= 1
test.at(2)= 2
test.at(3)= 3
test.at(4)= 4
test.at(5)= 5

test.at(0)= 0
test.at(1)= 1
test.at(2)= 2
test.at(3)= 3
test.at(4)= 4
test.at(5)= 5
test.at(6)= 57

test.at(0)= 0
test.at(1)= 12
test.at(2)= 1
test.at(3)= 2
test.at(4)= 3
test.at(5)= 4
test.at(6)= 5
test.at(7)= 57