Snippets Collections
enum string_code {
    eFred,
    eBarney,
    eWilma,
    eBetty,
    ...
};

string_code hashit (std::string const& inString) {
    if (inString == "Fred") return eFred;
    if (inString == "Barney") return eBarney;
    ...
}

void foo() {
    switch (hashit(stringValue)) {
    case eFred:
        ...
    case eBarney:
        ...
    }
}
star

Tue Feb 06 2024 13:03:33 GMT+0000 (Coordinated Universal Time) https://stackoverflow.com/questions/650162/why-cant-the-switch-statement-be-applied-to-strings

#cpp #switch_alternative_for #string

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension