fork download
  1. //@Author Damien Bell
  2. #include <iostream>
  3. #include <vector>
  4. using namespace std;
  5.  
  6.  
  7. int main(){
  8.  
  9. vector<int> vInts;
  10.  
  11. for(int i=0; i<5; i++){
  12. vInts.push_back(i);
  13. }//0,1,2,3,4
  14.  
  15. vector<int>::iterator iter;
  16.  
  17. for(iter = vInts.begin(); iter < vInts.end(); iter++){
  18. cout << *iter <<endl;
  19. }
  20. cout <<endl << endl;
  21.  
  22.  
  23. vector<int>::reverse_iterator rIter;
  24. for(rIter = vInts.rbegin(); rIter < vInts.rend(); rIter++){//Rbegin- reverse begin. The end of the vector is set as the beginning
  25. cout << *rIter <<endl;//Rend - Set the beginning of the vector to the end.
  26. vInts.pop_back();//Removing the last element from the vector
  27. }
  28. cout <<endl << endl;
  29. for (int i=0; i < vInts.size(); i++){
  30. cout << vInts[i]<<endl;
  31. }
  32.  
  33. cout << "\n\nHuh, that's odd";
  34.  
  35.  
  36.  
  37.  
  38.  
  39. return 0;
  40. }
  41.  
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:29: warning: comparison between signed and unsigned integer expressions
stdout
0
1
2
3
4


4
3
2
1
0




Huh, that's odd