How to capture a parameter after some string in command line?
./executable.out -apps path_to_out
In the above code I want to store path_to_out in a string variable. What is the efficient way of doing that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It kind of depends what kind of options you want. If you are willing to have only single-letter options, you can use the C library function
getoptto parse the command line. If you would like long options (e.g.,--apps), you can usegetopt_long, but this is a GNU extension that will not port well. If you want really, really fancy option parsing, you can use something like GLib.Of course, you can just roll your own, iterating over the arguments from 1 to
argcand, when you encounter-apps, check thati+1 < argcand grab the next argument.