Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- using namespace std;
- int main()
- {
- vector <string> langs = { "Python", "C++", "C", "Java", "C#" };
- auto it = end(langs);
- while (it != begin(langs))
- {
- --it;
- cout << *it << " ";
- }
- //##################################################################################
- // Можно ли внести декремент в условие цикла?
- /*while (it-- != begin(langs))
- {
- cout << *it << " ";
- }*/
- // Как нельзя
- /**end(c);
- auto it = end(c); ++it;
- auto it = begin(c); --it;*/
- //##################################################################################
- // Отличие итераторов от ссылок
- // Итераторы могут указывать в никуда - на end
- // Итераторы можно перемещать на другие элементы:
- vector<int> numbers = { 1,3,5 };
- auto it = numbers.begin();
- ++it; // it указывает на 3
- int& ref = numbers.front();
- ++ref; // теперь numbers[0] == 2
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement