image.png

    1. class MyCin
    2. {
    3. private:
    4. bool status;
    5. public:
    6. MyCin():status(true){}
    7. MyCin & operator >> (int & n) {
    8. if (!status) return *this;
    9. cin >> n;
    10. if (n == -1) status = false;
    11. return *this;
    12. }
    13. operator bool() { return status; }//类型转换函数
    14. };
    • 主要是bool类型转换运算符