Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8395735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:22:34+00:00 2026-06-09T20:22:34+00:00

I am using boost::program_options to parse argv . I expect both -c and –config

  • 0

I am using boost::program_options to parse argv. I expect both -c and--config

  boost::program_options::options_description description("Utility");
  description.add_options()
    ("help,h", "display this message")
    ("config,c", boost::program_options::value<std::string>(), "Path to configuration file")
    ("config-type", boost::program_options::value<std::string>()->default_value("json"), "type of configuration file (json|xml)")
    ("verbose,v", boost::program_options::value<int>()->default_value(2), "verbosity(0 to 2)")
    ("thread,t",boost::program_options::value<int>()->default_value(0), (boost::format("Max Thread Count %1% to %2%(Processor cores of this machine) if not multi threaded") % 0 % boost::thread::hardware_concurrency()).str().c_str())
    ("action,a", boost::program_options::value<std::string>()->default_value("pack"), "action to perfoem (pack|unpack)");
  boost::program_options::positional_options_description positional_description;
  positional_description.add("action", -1);

  boost::program_options::variables_map var_map;
  boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(description).positional(positional_description).style(boost::program_options::command_line_style::unix_style).run(), var_map);
  boost::program_options::notify(var_map);

  if(var_map.count("help")){
    std::cout << description;
    return 1;
  }
  if(var_map.count("config") < 1){
    std::cout << "No Configuration file added" << std::endl;
    return 1;
  }

  if(var_map.count("action") < 1){
    std::cout << "Please specify an action to perfoem (pack|unpack)" << std::endl;
    return 1;
  }

but --config f or --config=f or--config="f" doesn’t work and prints No Configuration file added though -c f works.
also If I use --config without any argument it throws exception saying required parameter is missing in 'config-type' which already has a default parameter.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:22:35+00:00Added an answer on June 9, 2026 at 8:22 pm

    Your problem seems to be exactly the same as described here: boost::program_options – does it do an exact string matching for command line options?

    I am using ubuntu with boost 1.42 and ubuntu repo doesn’t have a
    higher version. but is 1.42 that buggy ?

    Yes.

    You can workaround the problem by swapping the specification of --config and --config-type.

    The cleaner solution is to upgrade Boost. Vladimir Prus in the mentioned SO answer says the bug is fixed in 1.45. From what you wrote I suppose you’re using Ubuntu 11.04 (Natty Narwhal). You can do either of the following:

    1. Install newer Boost packages from Ubuntu 11.10 (Boost 1.46) or Ubuntu 12.04 (Boost 1.48) – by temporarily substituting natty with oneiric or precise for 11.10 or 12.04 respectively in /etc/apt/sources.list
    2. Install newer Boost packages a PPA which contain Boost backports (like e.g. https://launchpad.net/~purplekarrot/+archive/ppa)
    3. Build Boost from source as Xeo suggested.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using boost::program_options like this: namespace po = boost::program_options; po::options_description desc(Options); desc.add_options() (help,?,
I'm using boost::program_options to implement a command-line utility with this syntax: myutil command [--in
I'm writing a small C++ program using Boost's 'program_options' support. The following code: boost::program_options::options_description
I'm using boost::program_options and it suffers from the same as many other c++ libs,
Using boost::program_options, I can not get my own option type to compile when it
I am using boost::program_options and want to pass domain-like options to my program. Such
I want to read an integer array from console using boost::program_options. The length of
Using Boost Program Options, how do you get the string equivalent of argv[0]?
I'm using boost::program_options in my program. I want to make a certain flag mandatory.
I'm using Boost Program Options Library to parse the command line arguments. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.