This assignment is driving me insane!
I have a text file that looks like this:
Code:
3
CODE TIME DESCRIPTION
CODE TIME DESCRIPTION
CODE TIME DESCRIPTION
4
CODE1 CODE2 TIME1 TIME2
CODE1 CODE2 TIME1 TIME2
CODE1 CODE2 TIME1 TIME2
CODE1 CODE2 TIME1 TIME2
All of the codes are a 3 letter code, the times are in the form 00:00 and the description is the full version of the code. The first number tells you how many lines follow it and the second tells how many lines follow that.
I'm trying to read the file one line at a time, by reading the first line, the next group of lines, the next number line and the last lines. But I'm stuck due to the line number having to be converted to a string. Is there any way of using an int for the line number?
Here's my code so far:
Code:
ifstream inFile;
inFile.open(fileName.c_str(), ios::in);
if(!inFile) {
cerr << "Error: can't open input file" << fileName << endl;
exit(1);
}
int noOfAirports;
string aLine = "1";
//Reads line 1 of file to find out how many airports there are
while(getline(inFile, aLine)) {
inFile >> noOfAirports;
}
int lineNo = 2 + noOfAirports;
string bLine;
stringstream out;
out << lineNo;
bLine = out.str();
//code needs to go here to read next group of lines, something along the lines of for(int i=2; i <(lineNo); i++)
int noOfFlights;
//Reads file to find out how many flights there are
while(getline(inFile, bLine)) {
inFile >> noOfFlights;
}
//code here some sort of loop to read from noOfFlights + 1 to inFile.eof()
inFile.close();