This example illustrates how to use the range-based for loop introduced in C++11.
cppCopy code#include <iostream>
#include <vector>
int main() {
std::vector<int> numbers = {10, 20, 30, 40, 50};
// Using a range-based for loop
for (const auto& num : numbers) {
std::cout << num << " "; // Output: 10 20 30 40 50
}
std::cout << std::endl;
return 0;
}
Leave a Reply