Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 0.84 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using a nested vector in C  
  2. std::vector<std::vector<int> >::const_iterator’ has no member named ‘begin’
  3.  std::vector<std::vector<int> >::const_iterator’ has no member named ‘end’
  4.        
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <vector>
  8. #include <string>
  9.  
  10. using namespace std;
  11.  
  12. typedef vector<int> vector1D ;
  13. typedef vector<vector1D > vector2D ;
  14.  
  15. void showarr(const vector2D& v)
  16. {
  17.     for (vector<vector1D >::const_iterator it1 = v.begin(); it1 != v.end(); ++it1) {
  18.         for(vector<int>::const_iterator it2 = *it1.begin(); it2 != *it1.end(); ++it2) {
  19.             cout<<*it2<<endl;
  20.         }
  21.     }
  22. }
  23. int main(int argc, char *argv[])
  24. {
  25.     int rownum;
  26.     cin>>rownum;
  27.     vector2D a;
  28.     for ( int i = 0 ; i < rownum ; i++) {
  29.         a.push_back(vector1D(rownum,0));
  30.     }
  31.     showarr(a);
  32.     return 0;
  33. }
  34.        
  35. *it1.begin()
  36.        
  37. it1->begin()