Take it in as a string. Then, find the colons and break the string up to get what you need.
Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393
To get what you want, you need to read it as a string, and then parse the string. Some example :
string str;
cin >> str; //for example assume user enters 11:22:33
string::size_type hourEndPosition = str.find_first_of(":");
int hours = atoi( str.substr(0,hourEndPosition) );
string::size_type minuteEndPosition = str.find_first_of(hourEndPosition+1,minuteEndPosition);
int minutes = atoi( str.substr(hourEndPosition, minuteEndPosition - hourEndPoisition);
//.similar for seconds
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
>>>string str; cin >> str
You might consider using getline(cin,str) just in case the user might try to enter something like 05 : 25 : 60 . Notice the spaces.
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608