Check out the atoi() function which converts a string to an integer. However, you might not need to do that.
The method you use to read input from a file can be tailored based on how the input file is organized. In your case, the input file might look something like this:
M 8:00pm 30
T 7:00am 12
W 6:12am 52
You can't read all the data into a numerical type because there are characters in the input. You can use a string type, but then you have the problem of trying to perform calculations on non-numerical types. You can use atoi() to solve that problem, but there is an easier way: read input into more than one variable. You could declare three variables like this:
char day = 0;
string time;
int minutes = 0;
and then read in data into each of those variables:
Code:
while(!infile.eof())
{
infile>>day;
infile>>time;
infile>>minutes;
//perform calculations and output
//the variables and the calculations
}
"how do I tell it to take all the numbers, like the 6 & the 4, and stop at the next space?"
The >> operator is defined so that it skips any whitespace preceeding the input, and it will stop reading when it encounters a space. So your input file can look like this and it won't make a difference:
Code:
M 8:00pm 30
T 7:00am 12
W 6:12am 52