Re: Trouble With Retrieving A std::string From boost::program_options
Starfox wrote:
[color=blue]
> The Following Code:
>
> //Setup the options
> string InputName, OutputSkeletonName, OutputModelName;
> program_options::options_description OptionDesc("Available Options");
> OptionDesc.add_options()
> ("help", "produce help message")
> ("input,I", program_options::value<string>(&InputName), "Input[/color]
Ok, the Input-Parameter following after "-I" should be taken as an string.
[color=blue]
> md5mesh File")
> ("out-skl,S", program_options::value<string>(&OutputSkeletonName ),
> "Output Skeleton File")
> ("out-mdl,M", program_options::value<string>(&OutputModelName),
> "Output Model File");
> program_options::variables_map OptionMap;
> program_options::store(program_options::parse_comm and_line(argc, argv,
> OptionDesc), OptionMap);
> if(OptionMap.count("help"))
> {
> cout << OptionDesc;
> return -2;
> }
> string t = OptionMap["I"].as<const char*>(); //CRASH[/color]
What do you want to do? You've advised boost to take the parameter for "-I"
as a string, after that you asked the program to read it as an "const
char*" and at least you assign the result to a string.
[color=blue]
> Crashes at the last line, even if i replace the const char* with
> std::string. I'm using VC++ 2005 on Windows XP SP2 and BOOST 1.32.0 .
> Any ideas?[/color]
Depends on what do you want to do. Ever tried the mucher shorter form:
string t = InputName;
(even if it doesn't make sense for me...)
Mathias |