Shift + Enter · Bắt đầu / bắt đầu lại
Đọc hướng dẫn đoạn mã
- Ngôn ngữ lập trình
- C++
- Độ khó
- Trung bình
Use a range-based loop to total vector values.
#include <iostream>
#include <vector>
int main() {
std::vector<int> values{4, 8, 15, 16, 23, 42};
int total = 0;
for (int value : values) {
total += value;
}
std::cout << total << '\n';
}