How to convert cPP strings to enumerations

how to convert a string to an enumerated type in cPP?

for example:

enum City{
    BEIJING,
    SHANGHAI,
    GUANGZHOU
}

//
City string_to_enmu(string str,City c);
CPP
May.22,2021
There is no good method for

. The enumeration of cPP is a simple type without name and other information. Use if else. If this enumeration is very large, you can consider doing a map, to speed up the execution efficiency first, but there are only three enumerations, the difference is not big.


is invited. The answer from i38me upstairs is all right.

Menu