I found out that using the getline
works way better.
// Read file.
{
ifstream file(filePath + fileName);
string line;
// Read by line.
for (int k = 0; k < Th.nv; k++){
getline(file, line);
temperatureField(k) = atof(line);
}
}