#include <iostream>
#include <fstream>
#include <string>
#include <stack>
#include <queue>
usingnamespace std;
typedef pair<int,int> process; //process type
queue<process> TaskQ; //Queue contains all tasks
queue<int> CPUunitQ; // Queue contains all available CPU
void loadTaskQ(string filename);
int main()
{
string filename;
cout<<"Please input the datafile: ";
cin>>filename;
loadTaskQ(filename);
return 0;
}
void loadTaskQ(string filename)
{
// This function loads the data from filename into global queue TaskQ
// each elementin TaskQ is a pair <int,int> (which has been typedef as process type)
ifstream inFile; // declare file stream variable
inFile.open( filename.c_str() ); // open data file
if ( inFile.fail() ) // check to see if file will open, terminate the program if file failed to open
{
cout << "Cannot open the input file." << endl;
exit( 1 );
}
while( !inFile.eof() ) // read in data until the end of the file
{
inFile >> TaskQ.push(process.first); // error
inFile >> TaskQ.push(process.second); // error
inFile.close(); // close input file
}
}
// error is illegal use of type as an expression
The txt input file looks like this:
1 2
2 2
3 4
4 3
5 6
.
.
.
19 4 end of file.
process is a type name , not an instance of that type. Declare an instance of process, read values into it, then push it into task. You also seem to be closing the file a bit early (line 39), right after reading the 1st pair.
1 2 3 4 5 6 7 8
process temp;
while( !inFile.eof() ) // read in data until the end of the file
{
inFile >>temp.first;
inFile >> temp.second;
task.push(temp);
}
inFile.close(); // close input file after reading all data