/ Published in: C++
example for iterator
Expand |
Embed | Plain Text
#include <iostream> #include <vector> #include <iomanip> using namespace std; struct Tuple { double attr1; double attr2; }; int main() { double a = 1.0; vector<Tuple> vec(50, Tuple()); for(vector<Tuple>::iterator it = vec.begin(); it != vec.end(); ++it) { it->attr1 = it->attr2 = a++; } Tuple arr[5][10]; vector<Tuple>::iterator it = vec.begin(); for(int i = 0; i < 5; ++i) { for(int j = 0; j < 10; ++j) { arr[i][j] = *it; ++it; cout << "(" << setw(2) << arr[i][j].attr1 << "," << setw(2) << arr[i][j].attr2 << ") "; } cout << '\n'; } cout << endl; }
You need to login to post a comment.
