How should I loop over the elements of a C++ container in reverse order? [duplicate]
问题 This question already has answers here : Iterating C++ vector from the end to the begin (11 answers) Closed 5 hours ago . Suppose I'm a newbie C++ programmer. I have a C++ container; say, a vector: std::vector<int> vec { 12, 34, 56, 78 }; I know I can iterate over all of the elements with a simple loop: for(std::vector<int>::size_type i = 0; i < vec.size(); i++) { std::cout << vec[i] << '\n'; } and maybe I've even learned a little about Modern C++, so I know I can use a ranged-for loop: for