What's the standard way of reading a "line of numbers" and store those numbers inside a vector.
file.in
12
12 9 8 17 101 2
Should I read the file line by line, split the line with multiple numbers, and store the tokens in the array ?
What should I use for that ?
#include <vector>
#include <fstream>
#include <iterator>
#include <algorithm>
std::vector<int> data;
std::ifstream file("numbers.txt");
std::copy(std::istream_iterator<int>(file), std::istream_iterator<int>(), std::back_inserter(data));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With