|
发表于 2020-3-30 00:15:01
|
显示全部楼层
#include <string>
#include <iostream>
#include <sstream>
using namespace std;
class Time
{
friend ostream &operator<<(ostream &output,Time &t)
{
cout<<t.hour<<":"<<t.minute<<":"<<t.second;
return output;
}
friend istream &operator>>(istream &input,Time &t)
{
string temp;
input >> temp;
istringstream iss;
iss.str(temp);
iss.str(temp.substr(0, 2));
iss >> t.hour;
iss.clear();
iss.str(temp.substr(3, 2));
iss >> t.minute;
iss.clear();
iss.str(temp.substr(6, 2));
iss >> t.second;
return input;
}
private:
int hour;
int minute;
int second;
};
int main(void)
{
Time t;
cin >> t;
cout << t << endl;
return 0;
} |
|