I am using the code from this answer to read lines of numbers (one number per line) from a file into a vector:
ifstream fs(file_name);
vector<double> v {istream_iterator<double>{fs}, istream_iterator<double>{}};
fs.close();
which works neatly and fine. My questions are:
- How does it work? @user470379 posted an "equivalent" piece of code by expanding it into a
while
loop. I understand the loop but I don't see the equivalence. - Why were people criticizing? Besides the delimiter or quote issues that I don't care about here, some people like @StudentT and @XanderTulip said it is highly inefficient. Since I don't know how it works, I cannot get the inefficient part. But I also don't think the delimiter issue can cause performance problem as stated by @StudentT ("...therefore not scalable...").
Thank you.