c++ - Trying to read command line switches with regex -


so trying read input command line in format fileusage.exe [switches] [folder] switches can typed in format long start -. example -c+j#r.

 int main(int argc, char *argv[])  {     cout.imbue(locale(""));  vector<char> theswitches; regex switches(r"reg(\-(c|\+|j|#|w|s|x|r|r|s|v|h)$)reg");  if (argc > 1) {      // search through command line args , find matching switches     if (regex_match(argv[1], switches))     {         theswitches.push_back(argv[1]);     }     else         cout << "didnt find switches" << endl;  } 

with code, able iterate on parameters. have removed $ match end of parameter list.

regex switches(r"reg(\-(c|\+|j|#|w|s|x|r|r|s|v|h))reg");  std::string s = "-c -s";  using reg_itr = std::regex_token_iterator<std::string::iterator>; (reg_itr it{s.begin(), s.end(), switches, {1}}, end{}; != end;) {     std::cout << *it++ << "\n"; } // outputs: // c // s 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -