#include#include int main() { std::vector vec = {1, 2, 3, 4, 5}; for (auto it = vec.begin(); it != vec.end(); it++) { std::cout << *it << " "; } std::cout << std::endl; return 0; }
#includeIn this example, we have created a vector of integers and initialized it with values. We have used the begin function to initialize an iterator and then used it to modify the first element of the vector to 10. Package library: Standard Template Library (STL)#include int main() { std::vector vec = {1, 2, 3, 4, 5}; vec.begin()++; // Increment iterator to point to second element *vec.begin() = 10; // Modify first element to 10 for (auto val : vec) { std::cout << val << " "; } std::cout << std::endl; return 0; }