How to split a string from an input file into 2 int values

I have this kind of input file
Mo 13:30 16
Mo 8:15 35
Tu 7:50 20
We 17:45 30
Th 8:00 45
Su 23:50 30

13:30 is the time. Now I want to separate this string into 13 and 30, and then convert 13 into int hour, and 30 into int minute. Is there a nice way to do this?

Easily.

1
2
3
4
5
6
string s = "13:30";
istringstream ss( s );
int hour, minute;
ss >> hour;
ss.get();
ss >> minute();

Hope this helps.
I tried it and it said minute cannot be use as a function?

Edit: I took out the () from ss >> minute; and it seems like it worked
Last edited on
Yes, sorry, that was a typo of mine. Glad to have helped.
Topic archived. No new replies allowed.