boost::program_options を使用して、複数のコマンド ライン引数を解析したいと考えています。ただし、一部の引数は二重引用符で囲まれた文字列です。これは私が持っているものです -
void processCommands(int argc, char *argv[]) {
std::vector<std::string> createOptions;
boost::program_options::options_description desc("Allowed options");
desc.add_options()
("create", boost::program_options::value<std::vector<std::string> >(&createOptions)->multitoken(), "create command")
;
boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
boost::program_options::notify(vm);
if(vm.count("create") >= 1) {
std::string val1 = createOptions[0];
std::string val2 = createOptions[1];
...
// call some function passing val1, val2.
}
}
これは私がするときにうまくいきます
cmdparsing.exe --create arg1 arg2
しかし、私がするときは動作しません
cmdparsing.exe --create "this is arg1" "this is arg2"
Windows コマンドラインから。2 番目のオプションでは["this" "is" "arg1" "this" "is" "arg2"]
、createOptions ベクトルに変換されます。したがって、と
の代わりにと をそれぞれval1
取得"this"
します。val2
"is"
"this is arg1"
"this is arg2"
boost::program_option を使用してこれを機能させるにはどうすればよいですか?