enum type can not accept cin command

前端 未结 3 2136
眼角桃花
眼角桃花 2020-12-03 09:43

Look t this code plz:

#include 
using namespace std;
int main()
{

    enum object {s,k,g};
    object o,t;

    cout << \"Player One:          


        
3条回答
  •  春和景丽
    2020-12-03 09:45

    There is no operator>>() for enum. You can implement one yourself:

    std::istream& operator>>( std::istream& is, object& i )
    {
        int tmp ;
        if ( is >> tmp )
            i = static_cast( tmp ) ;
        return is ;
    }
    
    
    

    Of course, it would be easier if you just cin an integer and cast yourself. Just want to show you how to write an cin >> operator.

    提交回复
    热议问题