Given the following program:
#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;
}
Is there a way, using STL, to write this without the explicit while loop (e.g., using a copy() algorithm and an inserter?).
I haven't found a way to do this when the number of elements is read at runtime (as in the variable 'n', here).