String to enum in C++

后端 未结 10 1635
渐次进展
渐次进展 2020-11-28 07:15

Is there a way to associate a string from a text file with an enum value?

The problem is: I have a few enum values stored as string in a text file which I read on

10条回答
  •  旧巷少年郎
    2020-11-28 07:51

    I agree with many of the answers that std::map is the easiest solution.

    If you need something faster, you can use a hash map. Perhaps your compiler already offers one, such as hash_map or the upcoming standard unordered_map, or you can get one from boost. When all the strings are known ahead of time, perfect hashing can be used as well.

提交回复
热议问题