maybe, I should ask question about how to overload
istream operator >> for an enum type?
Last edited on
For a straight-up enum, just read the string and compare it to an array of strings. The index of the match is the enum value, and a simple cast will get the proper value.
For an enum with arbitrary values, you also need to provide a lookup table to convert between the match index and the enum value.
For typed enums, you can do it directly in an overloaded operator >>, but for the old enums I would wrap it in an input manipulator.
Hope this helps.
Thanks, Duoas! I want to go with the overloaded operator >> , how can I do that?
Oh, My god, Thanks a lot, Duoas! I think I need sometime to digest it! Thanks!