-
June 13th, 2014, 11:38 AM
#16
Re: Parsing CL arguments and Function call queue
Again, if you want to do something (parse command line arguments) a non-standard way then you have to create your own non-standard (parsing) mechanism!
What will you use to parse (some STL or Win API or C-runtime or some other functions/methods) is up to you!
Victor Nijegorodov
-
June 13th, 2014, 02:24 PM
#17
Re: Parsing CL arguments and Function call queue
Have a look at this. IT will parse commands of the form cmnd a,b,c d,e,f which is what I think you're after.
Code:
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const char separ = ',';
typedef vector<string> VSTR;
typedef vector<VSTR> VVEC;
int main(int argc, char* argv[])
{
VVEC vargs;
for (int a = 1; a < argc; a++) {
string line = argv[a];
VSTR varg;
for (size_t st = 0, pos = line.find_first_not_of(' '), last = 0; (last += (pos = line.find(separ, st)) == string::npos) < 2; st = pos + 1, last += (pos == string::npos))
varg.push_back(line.substr((st = line.find_first_not_of(' ', st)), line.find_last_not_of(' ', pos - 1) - st + 1));
vargs.push_back(varg);
}
for (int a = 0; a < vargs.size(); a++) {
copy(vargs[a].begin(), vargs[a].end(), ostream_iterator<string>(cout, " "));
cout << endl;
}
return 0;
}
An example is
Code:
c:\MyProgs>test12 qw,as,df er,ty,ui,op
qw as df
er ty ui op
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|