I have tried to create a C++ argument parsing system like it is in Python (--tag
or -t
and later the value), but my code will not work. I have doubled and tripled checked it and nothing seems to be wrong with it.
Basically, what it does is it gets the arguments and loops through them all until it finds one that is either --dict
or -d
and then the argument++
is saved in the dict
variable.
Here's the code:
#include <iostream>
#include <string>
int main (int argc, char* argv[]) {
for (int i=0; i<argc; i++) {
std::cout<<i<<" - "<<argv[i]<<std::endl;
if (argv[i] == "--dict" || argv[i] == "-d") {
std::string dict = argv[i++];
std::cout<<"Dictionary: "<<dict<<std::endl;
}
}
return 0;
}