If I have an enum like this:
enum Errors {
ErrorA = 0,
ErrorB,
ErrorC,
};
Then I want to print it out to console:
Errors anError = ErrorA;
std::cout << anError; // 0 will be printed
But what I want is the text "ErrorA". Can I do it without using if/switch? And what is your solution for this?
Using map:
Using array of structures with linear search:
Using switch/case:
Test the solutions: