This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
|
cpp:stl:iterators [2022/05/26 18:48] gthanos [STL Iterators] |
cpp:stl:iterators [2022/05/26 18:54] gthanos [STL Iterators] |
||
|---|---|---|---|
| Line 57: | Line 57: | ||
| #include < | #include < | ||
| #include < | #include < | ||
| + | #define SIZE 10 | ||
| int main () { | int main () { | ||
| - | std:: | + | std:: |
| int i=0; | int i=0; | ||
| | | ||
| Line 74: | Line 75: | ||
| </ | </ | ||
| * **Random Access Iterators: | * **Random Access Iterators: | ||
| - | <code cpp> | + | < |
| + | #include < | ||
| + | #include < | ||
| + | #define SIZE 10 | ||
| + | |||
| + | using namespace std; | ||
| + | |||
| + | int main() { | ||
| + | vector< | ||
| + | for(int i=0; i<SIZE; i++) | ||
| + | ints[i] = i+1; | ||
| | | ||
| - | vector< | + | vector< |
| - | while(true) { | + | while(it > ints.cbegin()) { |
| it -= 2; // move back by 2 elements | it -= 2; // move back by 2 elements | ||
| - | cout << *it1 << " "; | + | cout << *it << " "; |
| - | if(it1 <= ints.cbegin()) | + | if(it <= ints.cbegin()) |
| break; | break; | ||
| } | } | ||
| cout << endl; | cout << endl; | ||
| + | } | ||
| </ | </ | ||