fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <list>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8.  
  9. vector <int> iVec;
  10. list <int> iList;
  11. vector<int>::iterator vIt;
  12. list <int>::iterator lIt;
  13.  
  14. for(int i = 0; i < 10; i++){
  15. iVec.push_back(i*10);
  16. iList.push_back(i*10);
  17. }//0, 10, 20, 30....90
  18.  
  19. lIt = iList.begin();
  20. vIt = iVec.begin();
  21. // 0, 10, 20, 30, 40, 50....
  22. // ^ -- iterator points to 0, lIt++; lIt+=5;
  23. // 0, 10, 20, 30, 40, 50....
  24. // ^ -- iterator points to 0; vIt+=5;
  25.  
  26. vIt+=2;
  27. iVec.insert(vIt, 5, 5309);
  28.  
  29. lIt++; lIt++;
  30. iList.insert(lIt, iVec.begin(), iVec.end());
  31.  
  32.  
  33. cout << endl << endl <<"Vector Contents: " <<endl << endl;
  34. //Vector output loop
  35. for(int i=0; i < iVec.size(); i++){
  36. cout << iVec[i] << endl;
  37. }
  38.  
  39.  
  40.  
  41. cout << endl << endl <<"List Contents: " <<endl << endl;
  42. //List output loop
  43. for(lIt = iList.begin(); lIt != iList.end(); lIt++){
  44. cout << *lIt << endl;
  45. }
  46.  
  47.  
  48. return 0;
  49. }
  50.  
  51.  
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:35: warning: comparison between signed and unsigned integer expressions
stdout

Vector Contents: 

0
10
5309
5309
5309
5309
5309
20
30
40
50
60
70
80
90


List Contents: 

0
10
0
10
5309
5309
5309
5309
5309
20
30
40
50
60
70
80
90
20
30
40
50
60
70
80
90