My friend is working on a neural network project. Copying some code from this tutorial, he is using this part of the code for reading lines of numbers from a file into vectors:
void TrainingData::getTopology(vector<unsigned> &topology)
{
string line;
string label;
getline(m_trainingDataFile, line);
stringstream ss(line);
ss >> label;
if (this->isEof() || label.compare("topology:") != 0) {
abort();
}
while (!ss.eof()) {
unsigned n;
ss >> n;
topology.push_back(n);
}
return;
}
When compiling and running this using MinGW, the lines of numbers are read correctly. But when compiling and running this using WSL, the last number is repeated, i.e. reading 3 2 1
results in 3 2 1 1
being stored in the vector.
Why does it repeat with WSL? Shouldn't the EOF bit have been set once last number is read, so that it breaks out of the while loop?