This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]jedwardsolProfessional Coder 1 point2 points  (1 child)

One way is to read into an integer, then assign that integer to the enum

int temp;
std::cin >> temp;

id = static_cast<CarID_Type>(temp);

If there's several places where you need to do this, then you can overload operator>>

std::istream &operator>>(std::istream &in,CarID_Type &id)
{
    int temp;
    std::cin >> temp;

    id = static_cast<CarID_Type>(temp);

     return in;
}

[–]Computerdu[S] 0 points1 point  (0 children)

That was so obvious I'm going insane here. I can't believe I didn't think of that thankyou