Reading integers from file skipping some chars

Hello,
I am learning now the C++ language and I have some problems on reading files.
I have to read a full-format time (hh:mm:ss) and what i want is to store on three int variables the hour, minutes and seconds.

Here is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<iostream>
#include<fstream>
using namespace std;

int main()
{
ifstream input("time.in", ios::in);
ofstream output("time.out", ios::out);
int hours, minutes, seconds;

input >> hours >> minutes >> seconds;

input.close();
output.close();
cout << "Hours: " << hours << " Minutes: " << minutes << " Seconds: " << seconds << endl;

}


The input file:
 
02:21:15

And the output:
Hours: 2 Minutes: 0 Seconds: 32625

The correct result should have been: Hours: 02, Minutes: 21, Seconds: 15
So what i need is to skip the ":" and save the numbers in integers vars.
Thank you in advance.
You can try it this way:
1
2
char colon;
input >> hours >> colon >> minutes >> colon >> seconds;
So smart, so simple, Thanks man is working!
Topic archived. No new replies allowed.