我试图要求用户输入将被推入向量的数字,然后使用函数调用来计算这些数字。
为什么这不起作用?我只能数第一个数字。
template <typename T>
void write_vector(const vector<T>& V)
{
cout << "The numbers in the vector are: " << endl;
for(int i=0; i < V.size(); i++)
cout << V[i] << " ";
}
int main()
{
int input;
vector<int> V;
cout << "Enter your numbers to be evaluated: " << endl;
cin >> input;
V.push_back(input);
write_vector(V);
return 0;
}
原文由 Sean 发布,翻译遵循 CC BY-SA 4.0 许可协议