I need to save all arguments to a vector or something like this. I'm not a programmer, so I don't know how to do it, but here's what I've got so far. I just want to call a function system to pass all arguments after.
#include "stdafx.h"
#include "iostream"
#include "vector"
#include <string>
using namespace std;
int main ( int argc, char *argv[] )
{
for (int i=1; i<argc; i++)
{
if(strcmp(argv[i], "/all /renew") == 0)
{
system("\"\"c:\\program files\\internet explorer\\iexplore.exe\" \"www.stackoverflow.com\"\"");
}
else
system("c:\\windows\\system32\\ipconfig.exe"+**All Argv**);
}
return 0;
}
The argv parameter is an array of pointers to string that contains the parameters entered when the program was invoked at the UNIX command line.
main(int argc,char *argv[]) // version including the inputs {.... The input argv is an array of strings, one string per item. So argv[0] is the command name, argv[1] is the first input, etc. Numbers on the command line appear in argv as strings, not as numbers.
argv is of type char ** . It is not an array. It is a pointer to pointer to char . Command line arguments are stored in the memory and the address of each of the memory location is stored in an array. This array is an array of pointers to char .
i need to save all arguments to a vector or something
You can use the range constructor of the vector and pass appropriate iterators:
std::vector<std::string> arguments(argv + 1, argv + argc);
Not 100% sure if that's what you were asking. If not, clarify.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With