I am in a case when i am given two time formats hh:mm:ss to input.
I know that int
variables exctract from cin
until a non-integer is reached. This means that i can extract the hours easily, but then the character ":" would still be in the stream, which would cause a problem for the extraction of minutes.
I know i can use cin.ignore()
but since i have to input two time formats, the code just for the input would result very long and not seem too good.
Just to give you an idea:
int h,m,s, h2,m2,s2;
cin>>h;
cin.ignore();
cin>>m;
cin.ignore();
cin>>s;
cin>>h2;
cin.ignore();
cin>>m2;
cin.ignore();
cin>>s2;
I know that cin automatically ignores whitespaces. Is there a way to make it automatically ignore a specific character (in this case, the character ":")?