473,769 Members | 6,034 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble With Retrieving A std::string From boost::program_ options

The Following Code:

//Setup the options
string InputName, OutputSkeletonN ame, OutputModelName ;
program_options ::options_descr iption OptionDesc("Ava ilable 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> (&OutputSkeleto nName),
"Output Skeleton File")
("out-mdl,M", program_options ::value<string> (&OutputModelNa me),
"Output Model File");
program_options ::variables_map OptionMap;
program_options ::store(program _options::parse _command_line(a rgc, argv,
OptionDesc), OptionMap);
if(OptionMap.co unt("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?

Jul 25 '05 #1
2 2456
Starfox wrote:
The Following Code:

//Setup the options
string InputName, OutputSkeletonN ame, OutputModelName ;
program_options ::options_descr iption OptionDesc("Ava ilable Options");
OptionDesc.add_ options()
("help", "produce help message")
("input,I", program_options ::value<string> (&InputName), "Input
Ok, the Input-Parameter following after "-I" should be taken as an string.
md5mesh File")
("out-skl,S", program_options ::value<string> (&OutputSkeleto nName),
"Output Skeleton File")
("out-mdl,M", program_options ::value<string> (&OutputModelNa me),
"Output Model File");
program_options ::variables_map OptionMap;
program_options ::store(program _options::parse _command_line(a rgc, argv,
OptionDesc), OptionMap);
if(OptionMap.co unt("help"))
{
cout << OptionDesc;
return -2;
}
string t = OptionMap["I"].as<const char*>(); //CRASH
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.
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?


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
Jul 25 '05 #2
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?

Jul 25 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
2615
by: Jeff Flinn | last post by:
At the risk of raising the OT ire of some here, I'd like to know what might be done to raise the awareness of the boost libraries. I've found boost and it's libraries invaluable in my work for ~5 years now. The first two postings in this group this morning are addressed almost trivially by using libraries from www.boost.org. IMO, the functionality in boost increases the usability of C++ at least as much as the standard library does. ...
1
7791
by: Hardy | last post by:
Hi, just come into the boost world. just the first.cpp in the program_options examples, with many link error... devc++4.9.9.2, gcc 3.4.2, can I get your opinions on this problem? thank you~ make.exe -f "D:\temp\Makefile.win" all g++.exe -c main.cpp -o
0
402
by: Krivenok Dmitry | last post by:
I use boost program_options library in my project. But I have one trouble and can't solve it :( I writing simple wrapper class and use generic selector: /////////////////////////////////////////////////////////////////// // General options selector template <class T> void CmdLine::GetOption(const std::string& Name, T& var) { if (VariablesMap_.count(Name)) var = VariablesMap_.as<T>();
1
5386
by: cesco | last post by:
Hi, I'm using the boost library program_options for parsing the command line given to my program as described in the class Parameter: // Main.cpp #include "Parameter.h" using namespace std; int main(int ac, char* av)
0
2347
by: pallav | last post by:
hi i'm using the boost::program_options and i'm having some problems with syntax: the code in question is the following: vector<string> opt; po::options_description desc("Usage"); desc.add_options() ("help,h", "Print help message.")
0
1393
by: pallav | last post by:
i'm using the boost:rogram_options and i'm having some problems with syntax: the code in question is the following: vector<stringopt; po:ptions_description desc("Usage"); desc.add_options() ("nodes,n", po::value<vector<string (&opt)->default_value("*"), "Name of node(s) to print.") ;
1
3400
by: zade | last post by:
Hi all boost::program_options needs be builled into libraries, static or dynamic. I use MSVC7.1 to build the boost::program_options for my project .In my .cpp file , I write: namespace po = boost::program_options; struct CommandLineParser { CommandLineParser()
1
1819
by: Olaf | last post by:
Hi, I try to design a program which has to run on console. There is only one exe/binary and depend on the calling name argv the different tasks/commands should be performed as aliases. It's the technique by busybox or linux lvm tools in C and avoids a bunch of different binaries. Now I want to write those using C++ classes and boost. Ok, now I'm in design considerations. I have problems with the API for this purpose.
42
4551
by: barcaroller | last post by:
In the boost::program_options tutorial, the author included the following code: cout << "Input files are: " << vm.as< vector<string() << "\n"; Basically, he is trying to print a vector of string, in one line. I could
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8873
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.