i am having a problem with reading input from a text file that looks like this:
ID: 3628372 • Letter: I
Question
i am having a problem with reading input from a text file that looks like this:9 1 1
1.2 -2.3 0.4
-2 -3 -4
+0 -2 8.85
2.345
The problem is that i am not reading the last line (2.345).
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
double a, b, c;
ifstream input("quadratic.dat");
input>>a>>b>>c;
while (!input.eof())
{
cout<<"a: "<<a<<" b:"<<b<<" c:"<<c<<endl;
input>>a>>b>>c;
}
return 0;
}
Explanation / Answer
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
double a, b, c;
ifstream input("quadratic.dat");
while (!input.eof())
{
input>>a>>b>>c;
cout<<"a: "<<a<<" b:"<<b<<" c:"<<c<<endl;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.