What is the correct answer?
Instead of looping on eof, try looping on the actual extraction of data.
1 2 3 4 5 6 7
|
double dummy1, dummy2, dummy3, dummy4; // better names???
while (read_file >> dummy1 >> dummy2 >> dummy3 >> dummy4)
{
std::cout << "Data read successfully, dummy1 = " << dummy1 << "\n";
number_of_rows++;
}
|
Edit: On line 22, you're putting commas in your file.
This will cause simple whitespace-delimited extraction with istream operator>> to fail.
If your data is comma delimited, use a combination of
getline with comma as the delimiter, and use
stod
to convert string to double.
http://www.cplusplus.com/reference/string/string/getline/
http://www.cplusplus.com/reference/string/stod/
Or, use istream operator>>, but skip a character for the comma between each use of >>.
1 2 3
|
file_write_x_and_y_dat << endl;
file_write_x_and_y_dat.flush();
|
endl already flushes the file, so calling it twice in a row is just wasteful.
But you don't need to use endl or flush; it will be done automatically. Doing it more than necessary is just lowering performance.