我重载了 I/O 操作符:
struct Time {
int hours;
int minutes;
};
ostream &operator << ( ostream &os, Time &t ) {
os << setfill('0') << setw( 2 ) << t.hours;
os << ":";
os << setfill('0') << setw( 2 ) << t.minutes;
return os;
}
istream &operator >> ( istream &is, Time &t ) {
is >> t.hours;
is.ignore(1, ':');
is >> t.minutes;
return is;
}
我想知道当我调用cin >> time
编译器如何确定is &is
参数时。这是我的main()
程序:
operator>>( cin, time );
cout << time << endl;
cin >> (cin , time);
cout << time << endl;
cin >> time; //Where is cin argument???
cout << time << endl;