Did you read the man page? The option argument, if there is one, will be in the global variable optarg
.
Even the link you have there says the same. Your option string doesn't need the leading ::
either - only the ones after the letters mean anything.
Edit: Here's a complete working example of what it looks like you're trying to do:
#include <unistd.h>
#include <iostream>
int main(int argc, char **argv)
{
int ch;
while ((ch = getopt(argc, argv, "v:")) != -1)
{
switch (ch)
{
case 'v':
std::cout << optarg << std::endl;
break;
}
}
return 0;
}
And output:
$ ./example -v abcde
abcde