c++中如何输入11:02:01这样的格式;换句话数就是如何在c++中将多个数字与符号同时输入

我想定义三个变量hour,minute,second分别代表时间中的小时,分钟,秒

我想输入时以hour:minute:second的形式输入

请问我该如何输入

int a, b, c; char ch; cin >> a >> ch >> b >> ch >> c;

或者

int a, b, c; scanf("%d:%d:%d", &a, &b, &c);

#include <iostream>

using namespace std;

cin>>hour<<":">>minute>>":">>second;

 

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream>

using namespace std;
 
int main()
{
    char str[9] = {0};
    char hour[3] = {0};
    char minute[3] = {0};
    char second[3] = {0};
    cin>>str;
    //strcpy(str,"11:01:02");
    sscanf(str,"%[^:]:%[^:]:%[^:]",hour,minute,second);
    printf("%s:%s:%s\n",hour,minute,second);
    return 0;
}