Greetings all.
I have a text file named data.txt . data.txt contains "double" numbers, one in each line. My attempt is to:
1. check how many lines are in data.txt
2. declare a double array of proper size
3. copy data from txt file line by line into that array
But when I print the array out it results in erroneous small random numbers, instead of those from data.txt. Here is my code:
Thank you for your answer. You are right, this was the error. But I can't manage to modify code from the example you linked to work for my case. in these lines :
is.seekg (0, is.end);
int length = is.tellg();
is.seekg (0, is.beg);
the "length" is much too big, it probably reads single characters. The initial code that I have posted works fine for giving the right number for "number_of_lines", but storing in array doesn't function.
I would like the full number in a line to be read as a whole and placed in an array.
Do you know what function I could use for this ? Thank you.