c++ enum and using them to input from user

前端 未结 3 1997
时光说笑
时光说笑 2021-02-08 05:34

I have an enum in my code that is the following: enum Status {In-Active, Active};. A status object is passed to a Person object as a parameter, so I wa

3条回答
  •  甜味超标
    2021-02-08 05:51

    You can't read enum values directly, you'll need a std::map that maps user input to an enum value.

    std::map m;
    m["In-Active"] = In-Active;
    m["Active"] = Active;
    
    std::string sstatus;
    cin >> sstatus;
    Status status = m[sstatus];
    

提交回复
热议问题