{"pageProps":{"code":{"CMakeLists.txt":{"name":"CMakeLists.txt","content":"add_executable(constness-reverse constness-reverse.cpp)\r\n\r\nadd_executable(stream-iterators stream-iterators.cpp)\r\n\r\nadd_executable(vector-iterator vector-iterator.cpp)\r\n","path":"code/6771/26T2/2.2/CMakeLists.txt","fileext":"txt"},"constness-reverse.cpp":{"name":"constness-reverse.cpp","content":"#include <iostream>\r\n#include <vector>\r\n\r\nint main()\r\n{\r\n    std::vector<int> ages;\r\n    ages.push_back(18);\r\n    ages.push_back(19);\r\n    ages.push_back(20);\r\n\r\n    // type of iter would be std::vector<int>::iterator\r\n    for (auto iter = ages.begin(); iter != ages.end(); ++iter) {\r\n        (*iter)++; // OK\r\n    }\r\n\r\n    // type of iter would be std::vector<int>::const_iterator\r\n    for (auto iter = ages.cbegin(); iter != ages.cend(); ++iter) {\r\n        //(*iter)++; // NOT OK\r\n    }\r\n\r\n    // type of iter would be std::vector<int>::reverse_iterator\r\n    for (auto iter = ages.rbegin(); iter != ages.rend(); ++iter) {\r\n        std::cout << *iter << \"\\n\"; // prints 20, 19, 18\r\n    }\r\n\r\n    // Can also use crbegin and crend\r\n}","path":"code/6771/26T2/2.2/constness-reverse.cpp","fileext":"cpp"},"stream-iterators.cpp":{"name":"stream-iterators.cpp","content":"#include <fstream>\r\n#include <iostream>\r\n#include <iterator>\r\n\r\nint main()\r\n{\r\n    std::ifstream in(\"data.in\");\r\n\r\n    std::istream_iterator<int> begin(in);\r\n    std::istream_iterator<int> end;\r\n    std::cout << *begin++ << \"\\n\"; // read the first int\r\n\r\n    ++begin; // skip the 2nd int\r\n    std::cout << *begin++ << \"\\n\"; // read the third int\r\n    while (begin != end) {\r\n        std::cout << *begin++ << \"\\n\"; // read and print the rest\r\n    }\r\n}","path":"code/6771/26T2/2.2/stream-iterators.cpp","fileext":"cpp"},"vector-iterator.cpp":{"name":"vector-iterator.cpp","content":"#include <iostream>\r\n#include <string>\r\n#include <vector>\r\n\r\nint main()\r\n{\r\n    std::vector<std::string> names;\r\n    for (auto iter = names.begin(); iter != names.end(); ++iter) {\r\n        std::cout << *iter << \"\\n\";\r\n    }\r\n    for (std::vector<std::string>::iterator iter = names.begin();\r\n         iter != names.end(); ++iter) {\r\n        std::cout << *iter << \"\\n\";\r\n    }\r\n}","path":"code/6771/26T2/2.2/vector-iterator.cpp","fileext":"cpp"}}},"__N_SSG":true}