Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 25th, 2005, 09:15 AM
Starfox
Guest
 
Posts: n/a
Default Trouble With Retrieving A std::string From boost::program_options

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
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

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?

  #2  
Old July 25th, 2005, 09:35 AM
Mathias Waack
Guest
 
Posts: n/a
Default 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
  #3  
Old July 25th, 2005, 02:35 PM
Starfox
Guest
 
Posts: n/a
Default Re: Trouble With Retrieving A std::string From boost::program_options

I tried t = InputName, but InputName is completely empty!! it never
gets touched. and like i said, if i change the char* to a string it
still doesn't work. any ideas?

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles