I want to read the contents of a file and input them as variables. I have written this code:
while (!numbersList.eof())
{
numbersList >> type >> num1 >> num2;
Complex *object = new Complex(type,num1,num2);
cout << "For line number " << n << ": " << endl;
object->printAll();
cout << endl;
n++;
}
The only problem I am getting is that it prints out the last line in the file twice. For example, the file has 4 lines thusly:
p 100 0.80
r 50 50
p 20 4.8
r -100 25
but the result for the 'r -100 25' line is printed twice.
I tried using
while (numbersList >> type >> num1 >> num2)
but that only printed the first and third lines of the file...
Very stuck on this, any help much appreciated!