https://rentry.org/PPP2_p119c ⎗ ✓ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17// Code derived from Stroustrup's PPP2 book // § 4.6.1 Traversing a vector // -and beginning on p 119 #include <iostream> #include <vector> using std::cout; using std::vector; int main() { vector<int> v = {5, 7, 9, 4, 6, 8}; for (int x : v) // for each x in v cout << x << '\n'; } build & run: g++ -std=c++20 -O2 -Wall -pedantic ./ch_04/main_p119c.cpp && ./a.out sauce: Bjarne Stroustrup's PPP2 textbook /robowaifu/'s official C++ learning textbook thread Prev • Up • Next