What's the current best way to read in a 2D double array from a file?
The structure should be like this, I assume.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
void read_dataset(string datafile, vector <vector<double>>& data_arr){
ifstream datasource(datafile); // open the file
string single_char;
char delim = " ";
while (getline(datasource, single_char, delim)){
// as far as I understand,
// this will read char by char.
// what's the best way to do it without
// knowing the no. of elements in a row?
}
return;
}
while( std::getline( file, line ) ) Do I not need to specify the deliminter?
And if this already reads an entire line, what does the function parse_line do?
All these stream objects are confusing...
Last question to your explanation:
How is std::istream_iterator<double>{} an iterator to one-past-end if I don't even refer the targeted object, stm, anymore?
The default-constructed std::istream_iterator is known as the end-of-stream iterator. When a valid std::istream_iterator reaches the end of the underlying stream, it becomes equal to the end-of-stream iterator. https://en.cppreference.com/w/cpp/iterator/istream_iterator