Posted By

dirkchang on 08/10/12


Tagged


Versions (?)

iterator-example


 / Published in: C++
 

for example

  1. #include <iostream>
  2. #include <vector>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. int main() {
  7. int a = 1;
  8. vector<int> vec(50,0);
  9.  
  10. for(vector<int>::iterator it = vec.begin(); it != vec.end(); ++it) {
  11. *it = a++;
  12. }
  13.  
  14. int arr[5][10];
  15. vector<int>::iterator it = vec.begin();
  16. for(int i = 0; i < 5; ++i) {
  17. for(int j = 0; j < 10; ++j) {
  18. arr[i][j] = *it;
  19. ++it;
  20. cout << setw(4) << arr[i][j];
  21. }
  22. cout << '\n';
  23. }
  24. cout << endl;
  25. }

Report this snippet  

You need to login to post a comment.