#include#include int main() { std::vector vec = {1, 2, 3}; std::cout << vec[0] << "\n"; // Output: 1 vec.push_back(4); std::cout << vec[3] << "\n"; // Output: 4 return 0; }
#includeThis example demonstrates how to use iterators to traverse a vector and print its elements. Package Library: The std::vector is part of the C++ standard library, which comes with any C++ implementation.#include int main() { std::vector vec = {1, 2, 3}; for (auto it = vec.begin(); it != vec.end(); it++) { std::cout << *it << " "; } // Output: 1 2 3 return 0; }