Skip to content

Instantly share code, notes, and snippets.

@varvaruc
Created October 31, 2019 14:46
Show Gist options
  • Save varvaruc/4376b9dba0ddbc62ebd4a19358c0a8b0 to your computer and use it in GitHub Desktop.
Save varvaruc/4376b9dba0ddbc62ebd4a19358c0a8b0 to your computer and use it in GitHub Desktop.
int main(int argc, char **argv) {
vector<string> args(argv + 1, argv + argc);
string infname, outfname;
// Loop over command-line args
// (Actually I usually use an ordinary integer loop variable and compare
// args[i] instead of *i -- don't tell anyone! ;)
for (vector<string>::iterator i = args.begin(); i != args.end(); ++i) {
if (*i == "-h" || *i == "--help") {
cout << "Syntax: foomatic -i <infile> -o <outfile>" << endl;
return 0;
} else if (*i == "-i") {
infname = *++i;
} else if (*i == "-o") {
outfname = *++i;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment