030 你真的搞清楚为啥 while(cin >> n) 能成立了吗?


#include <iostream>
using namespace std;
class MyCin
{

    // 在此处补充你的代码
public:
    bool flag = false;
    MyCin & operator>> (int & n) {
        
        cin >> n;
        if (n == -1 || flag) {
            flag = true;
            return *this;
        }
        return *this;
    }
    operator bool() {
        return !flag;
    }

};
int main()
{
    MyCin m;
    int n1, n2;
    while (m >> n1 >> n2)
        cout << n1 << " " << n2 << endl;
    return 0;
}
posted @ 2022-02-23 17:52  icefield817  阅读(150)  评论(0编辑  收藏  举报