What stupid basic thing am I missing? we are to read in from a file that contains 10 lines.....name, age, etc....I can read in the file ok and print out the first line....I am having problems printing subsequent lines....HELP!! lol
//Acme Personel Report
//by PAtrick Nealey
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <fstream>
using namespace std;
const int MAX_NAME_LENGTH = 21;
const int MAX_DEPT_LENGTH = 16;
void getdata(ifstream& infile,ofstream& outputfile, char name[MAX_NAME_LENGTH], int& years, char department[MAX_DEPT_LENGTH], double& ytdpay);
int main()
{
char name[MAX_NAME_LENGTH];
int years;
char department[MAX_DEPT_LENGTH];
double ytdpay;
ifstream infile ("PJ811_personnel.txt");
if(!infile)
{
cerr <<"Could not open input file";
return -1;
}
ofstream outputfile ("PJ811_OUTPUT_Nealey.txt");
if (!outputfile)
{
cerr <<"Unable to open output file.\n";
}
outputfile <<setw(40)<<"Acme Personnel Report"<<endl<<endl;
outputfile <<left<<setw(20)<<"Employee"<<setw(8)<<"Years"<<left<<setw(15)<<"Department"<<right<<setw(10)<<"Year to"<<endl;
outputfile <<left<<setw(20)<<"Name"<<setw(8)<<"Emp."<<left<<setw(15)<<"Name"<<right<<setw(10)<<"Date Pay"<<endl<<endl;
getdata(infile,outputfile, name, years, department, ytdpay);
return 0;
}
void getdata(ifstream& infile,ofstream& outputfile, char name[MAX_NAME_LENGTH], int& years, char department[MAX_DEPT_LENGTH], double& ytdpay)
{
while (!infile.eof())
{
infile.get(name, MAX_NAME_LENGTH)>>ws;
infile >> years>>ws;
infile.get(department, MAX_DEPT_LENGTH)>>ws;
infile >> ytdpay;
}
outputfile <<left<<setw(20)<<name<<right<<setw(5)<<years<<" "<<left<<setw(15)<< department<<right<<setw(10)<<ytdpay<<endl;
}
I know using eof is not right....this is just where i decided to seek expert help