I would use an std::map
(or std::unordered_map
).
std::map<std::string, std::string> abbrs;
abbrs["Alabama"] = "AL";
abbrs["Alaska"] = "AK";
abbrs["Arizona"] = "AZ";
// ...
Then to look up a state's abbreviation, you'd do something like:
auto pos = abbrs.find(user_input_state_name);
if (pos == abbrs.end())
error_invalid_state_name(user_input_state_name);
else
abbreviation = *pos;
Note that in a typical case, you probably don't want to really hard-code all the state names and abbreviations into your source code. You probably want to have the names and abbreviations in an external configuration file.