Shift + Enter · 开始 / 重新开始
阅读代码练习指南
- 编程语言
- C++
- 难度
- 中等
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';
}