给定以下程序:
#include <vector>
#include <iostream>
using namespace std;
int main()
{
unsigned n;
vector<double> xvec;
cin >> n;
while (xvec.size() < n)
{
double x;
cin >> x;
xvec.push_back(x);
}
return 0;
}
有没有办法,使用 STL,在没有显式 while 循环的情况下编写它(例如,使用 copy() 算法和插入器?)。
当在运行时读取元素的数量时,我还没有找到一种方法来执行此操作(如变量'n',here)。