Read a whole line at a time (see e.g. std::getline
) then search backwards for the last whitespace (with e.g. std::string::find_last_of
). This is the whitespace that will separate the name from the number. Then use std::string::substr
to get the name into its own string, and parse the number with e.g. std::stoi
.
Note: The string with the full name will have one or more spaces at the end, you would want to remove those before using the string as a key.