I am currently learning C++. I am to read in data from a file into the table below. I am able to read the data in but in the table it does not like this:
StdID A1 A2 A3
030302 9 5 6
but rather as
030302
9
5
6
etc.
How do I format this correctly into the table? I tried setw but it didn't solve the problem.
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
int StdID=0, A1=0, A2=0, A3=0;
ifstream fin;
fin.open("data.txt");
if(!fin)
cout << "The file does not exist.";
else{
cout << "Std-ID A1 A2 A3 Min Max Avg\n";
cout << " ---------------------------------------------------\n";
while (!fin.eof())
{
fin >> StdID >> A1 >> A2 >> A3;
cout << setw(10) << StdID << endl;
cout << setw(10) << A1 << endl;
cout << setw(10) << A2 << endl;
cout << setw(10) << A3 << endl;
}
}
return 0;
}