I have a string which is coming from command line:
–m –d Tue –t 4 20 –u userid
I save it to a string by this:
string command;
for(int i=1; i<argc;i++){
string tmp = argv[i];
command += " "+ tmp + " ";
}
Now I want to manipulate this string to find if there is -u and if there is -u I want to see if the next value is starting with - or is a name. (it can be only -u or -u and a user name. In this example there is a user name)
if(command.find("-u",0)){
std::size_t found = command.find_first_of("-u");
cout<<found<<endl;
}
The output is 14 which is not the right place. My job is to find if there is a -u and if after -u is a user name or nothing or another command starting with -. I appreciate any idea or efficient code.
Edit: I must run this code on another server which I can not take any library instead of built-in g++ libraries.