Here's the code:

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

const int MAX_EMPLOYEE = 500;
enum PayType{H, S};
struct EMPLOYEE
{
	int idNumber;
	char name[21];
	double payRate;
	short int numberDependents;
	enum PayType;
};
int LoadMaster(EMPLOYEE& record);

int main(){
	int count;
	EMPLOYEE record;

	count = LoadMaster(record);

	cout << count;

	return 0;

}
int LoadMaster( EMPLOYEE& record){

	int count = 0;

	ifstream infile("ASG069_master.txt");
		if(!infile){
			cout << "Data file could not be found!\n";
			exit(1);
		}

		while(infile){
			infile >> record.idNumber;
			infile.get(record.name, sizeof(record.name));
			infile >> record.payRate >> record.numberDependents >> record.PayType;

			count++;
		}

		return count;
}

It's giving me an error with the "record.PayType"; The input file looks like this:
1234 Samuel Spade 15.5 2 H

The PayType represent either Hourly or Salaried - the H stands for Hourly while the S stands for Salaried. What am I doing wrong? The error message reads:

illegal as right side of '.' operator

If that's not how you would read it in, then how do you think it should be read in? Any help would be appreciated.

With this file format:
1234 Samuel Spade 15.5 2 H
the name field will always include a space, between the first and last name. Using get() will stop input at the space. You could try using getline(), but that seems too complicated since there is no single number of input char or delimeter to consistently use to stop input into the name. Therefore, I'd go back to the declaration of EMPLOYEE and change the name field to two separate strings, firstName and lastName. Then when it came time read in the name fields from the file I could use >> to read in all data fields because they would all be whitespace delimited. The alternative would be to use getline() to read in the entire line, or everything from the name field on, and then parse the line once read in. Then, by reading the input char by char you could use space count to help parse the line into a single name field, if you're wedded to having just a single name field in the struct.

But, the more pressing concern is the enum type. How do I use an enum type with the struct to read in the characters below. It would be simple if I used a character value, but the assignment stresses the use of an enum type.

read in as a char and check if it is 'H' or 'S'; set the enum accordingly.

PayType pt ;
  char c ;
  infile >> c ;
  if( c == 'H' ) pt = H ;
  else if( c == 'S' ) pt = S ;
  else infile.setstate( std::ios::failbit ) ;
This article has been dead for over six months. Start a new discussion instead.