Hey, I am having trouble with the file I/O part of this program. It seems to start at the end of the files contents and not go into the while loop.
#include "queue.cpp"
#include <iostream>
#include <fstream>
#include <iomanip>
/*******************************************
* class Priority *
* Takes input from file "queue1.dat" *
* If that input is '*' calls service() *
* If that input is '=' exits program *
* Otherwise, Sends that input to queue.cpp *
* Author: Kimberlie Davis *
* Version: 2/5/09 *
********************************************/
//using std::ifstream;
class Priority:public Queue
{
protected:
int priority;
char character;
public:
void service(void);
};
/*
* method service
* While queue is not empty,
* Output contents of queue
*/
void
Priority::service()
{
char output;
while(!empty())
{
output = takeAway();
cout << "Service:" << output << endl;
}
}
/*
* main method
* Takes input from file
* Tests if file exists
* Tests if file is open
* While not end of file, tests files contents
* Calls correct method based on file contents
*/
int main()
{
Priority priority;
Queue queue;
ifstream partin;
char charInput;
int numInput;
partin.open("queue1.dat");
if(!partin)
cout << "Error: Unable to find file" << endl;
if(partin.fail())
cout << "Error: Unable to open file!" << endl;
//file >> charInput;
//file >> numInput;
while(partin >> charInput >> numInput)
{
cout << charInput << " " << numInput << endl;
if(charInput == '*')
priority.service();
if(charInput == '=')
system("exit");
else
queue.addToQueue(numInput, charInput);
//file >> charInput;
//file >> numInput;
}
file.close();
system("pause");
}