int main(){
int nums[5]={1,2,3};
int totalSum = 0;
for (int num : nums) {
totalSum += num;
cout << totalSum <<endl;
}
输出:
6
(C++11标准下)
int main(){
int nums[5]={1,2,3};
int totalSum = 0;
for (int num : nums) {
totalSum += num;
cout << totalSum <<endl;
}
输出:
6
(C++11标准下)