optargでatoiを使用しようとしていますが、何でもかまいません。getopt_longが機能しない理由を理解しようとしています。switchステートメントを入力すると、optargはnullに設定され、そのままになります。コロンを確認しましたが、正しいです。これは私のコードです。
static struct option long_options[] =
{
{"algorithm", required_argument, 0, 'a'},
{"reverse", no_argument, 0, 'r'},
{"key", required_argument, 0, 'k'},
{"output", required_argument, 0, 'o'},
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{0, 0, 0, 0}
};
int option_index = 0;
int c;
//Getopt to get the correct options from the command line.
while ((c = getopt_long(argc, argv, "a:rk:o:hV", long_options,
&option_index)) != -1)
{
bool endOption = false;
if (endOption) break;
switch (c)
{
case 0:
{
endOption = true;
break;
}
case 'a':
{
if (optarg == "insertion") algorithm = 0;
break;
}
case 'r':
{
reverseFlag = true;
break;
}
case 'k':
{
while (optarg != " ")
{
if (optarg == ",")
{
optarg++;
}
else
{
sortOrder.push_back(atoi(optarg)); //error here
optarg++;
}
}
}
case 'o':
{
fileFlag = true;
break;
}
case 'h':
case 'V':
default:
{
cerr<<"You have entered an incorrect flag, do it better"<<endl;
break;
}
}
}
//その他//
私はダブルコロンと他のほとんどすべてを使用してみました。