一定要小心下标越界的问题。
subscrip is out of range .
else if (ivec.size() % 2 != 0 ){
for (vector<int>::size_type ix = 0; ix != ivec.size() - 1; ++ix){ // 这里红色的-1如果没有,就会造成下标越界。非常小的错误但是很不可以忽略。
if (ix % 2 == 0){
sum = ivec[ix] + ivec[ix+1];
cout << sum << endl;
}
}
cout << "the last one has no sum,and the last one is " << ivec[ivec.size() - 1] << endl;
}