Created
November 12, 2014 12:49
-
-
Save bananu7/f7f28b8f0d231078f21d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::map<std::string, std::string> parseOptions(std::vector<std::string> const& args) { | |
std::map<std::string, std::string> options; | |
auto it = args.begin(); | |
it++; // skip the file name | |
while(it != args.end()) { | |
if (it->at(0) == '-') { | |
std::string key = *it; | |
it++; | |
if (it == args.end()) { | |
options[key] = ""; | |
break; | |
} | |
std::string val = ""; | |
if (it->at(0) != '-') { | |
val = *it; | |
it++; | |
} | |
options[key] = val; | |
} | |
else { | |
throw std::runtime_error("Stray string in commandline"); | |
} | |
} | |
return options; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment