I have been trying to read a comma separated .txt file into an array and print it to console in C++. The txt file consists of two columns of double type data. For some reason the program runs, but gives blank output in the console. I want to know if I am doing something wrong. So far this is what I have:
I have been trying to read a comma separated .txt file into an array and print it to console in C++.
Please use code tags when posting code.
Code:
while(!getline(is, line).eof())
{
is >> x[i];
is >> y[i];
i++;
}
It is "line" that has the data. What your code does is read data into line using getline(), and then reads data again using operator >>. Are you not convinced that the data wasn't read the first time using getline()? If you debugged your code, you should have seen this. Are you using the debugger?
You should be taking "line" and then parse "line" into your tokens.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; October 16th, 2012 at 04:25 PM.
Bookmarks