inFile.open("journeydata.txt", ifstream::in+ ifstream::binary);
Your file is a text file. You don't want to open it in binary mode. What you want here is:
inFile.open("journeydata.txt", ifstream::in);
Also, the std::ifstream::open function opens the file for input by default, so, you could just write:
inFile.open("journeydata.txt");
My program has to take a time from the user in minutes, store it then have it read data and
take data from a file display it and work out if they can complete the trip in a certain time. |
Let's focus on the bold part first.
For a single record:
Getting the
journey value from the file looks ok. So does getting the
changes value. After that, you'll have to get some more values. Their number depends on the
changes value you just read. You'll need a for loop and (maybe) something to store these values in. Are you allowed to use std::vector? (Dynamic) Arrays?
For the entire file:
You'll have to keep reading records until you reach the end of file. You could do something like this:
1 2 3 4 5 6 7
|
while (getline(inFile, journey)) // while you can get a value for journey
{
// get number of changes
// get some pairs of numbers
// ignore some newlines
// store the data you got somewhere (maybe)
}
|
This may not be necessary, depending on what you want to do with the file data (it's not clear to me yet),
but if you want to, you could store it in several arrays or in an array of a properly defined struct.
Do you know how to / Are you allowed to use structs?
PS: Edit your post above, re-enter your code and put [co
de][/code] tags around it.