push_back的问题
程序代码:
int main() { vector<int> ivec; int ival, sum = 0; while(cin >> ival) ivec.push_back(ival); for(int ix = 0; ix < ivec.size(); ++ix) sum += ivec[ix]; int average = sum / ivec.size(); cout << "sum of " << ivec.size() << " elements: " << sum << ". average: " << average << endl; return 0; }
请问这一行的作用是什么ivec.push_back(ival;为什么这一行是必须的;我试图删除了这行,打印出sum和average的结果都是0.