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

  • SEARCH
  • Home
  • 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 952447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:53:45+00:00 2026-05-15T23:53:45+00:00

I am writing the following code on boost’s program_options (version 1.42). This seems straight-forward

  • 0

I am writing the following code on boost’s program_options (version 1.42). This seems straight-forward and taken pretty much as is from the tutorial. However, I get a “multiple_occurrences” error. Further investigation discovers that it’s (probably) the “filename” parameter that raises it.

The parameters I am giving are:

3 1 test.txt 100

I have no insight to it whatsoever.. any help will be appreciated.

po::options_description common("Common options");

common.add_options()
    ("help", "produce help message")
    ("motif_size", po::value<int>(&motif_size), "Size of motif (subgraph)")
    ("prob", po::value<double>(&prob), "Probably to continue examining an edge")
    ("filename", po::value<string>(&input_filename), "Filename of the input graph")
    ("repeats", po::value<int>(&n_estimates), "Number of estimates")
    ;

po::options_description all;
all.add(common);

po::positional_options_description p;
p.add("motif_size", 0).add("prob", 1).add("filename", 2).add("repeats", 3);

po::variables_map vm;   
po::store(po::command_line_parser(argc, argv).
      options(all).positional(p).run(), vm);
po::notify(vm); 
  • 1 1 Answer
  • 1 View
  • 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-05-15T23:53:46+00:00Added an answer on May 15, 2026 at 11:53 pm

    EDIT:

    the second parameter to po::positional_options_description::add is the max count, not the position. The position is implied in the order you specify the positional options. So

    p.add("motif_size", 0).add("prob", 1).add("filename", 2).add("repeats", 3);
    

    should be

    p.add("motif_size", 1).add("prob", 1).add("filename", 1).add("repeats", 1);
    

    Here’s a compilable snippet

    include <boost/program_options.hpp>
    
    #include <iostream>
    #include <string>
    
    int
    main(unsigned argc, char** argv)
    {
        namespace po = boost::program_options;
        po::options_description common("Common options");
    
        common.add_options()
            ("help", "produce help message")
            ("motif_size", po::value<int>(), "Size of motif (subgraph)")
            ("prob", po::value<double>(), "Probably to continue examining an edge")
            ("filename", po::value<std::string>(), "Filename of the input graph")
            ("repeats", po::value<int>(), "Number of estimates")
            ;
    
        po::options_description all;
        all.add(common);
    
        po::positional_options_description p;
        p.add("motif_size", 1).add("prob", 1).add("filename", 1).add("repeats", 1);
    
        po::variables_map vm;
        try {
            po::store(po::command_line_parser(argc, argv).
                    options(all).positional(p).run(), vm);
            po::notify(vm); 
        } catch ( const boost::program_options::error& e ) {
            std::cerr << e.what() << std::endl;
        }
    
        return 0;
    }
    

    and sample invocation.

    macmini:~ samm$ g++ parse.cc -lboost_program_options
    macmini:~ samm$ ./a.out 3 1 test.txt 100
    macmini:~ samm$ 
    

    My original answer is below.


    What version of program_options? I had the same problem using boost 1.39, to solve it I ended up using boost 1.42.

    Here’s a link to the ticket describing the problem, and a patch to apply if you don’t want to or can’t upgrade your copy of boost. To use the new functionality, do something like this

    try {
        // argument parsing goes here
    } catch ( const boost::program_options::multiple_occurrences& e ) {
        std::cerr << e.what() << " from option: " << e.get_option_name() << std::endl;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a small C++ program using Boost's 'program_options' support. The following code: boost::program_options::options_description
I'm writing the following code to read in a file from the filepath given
I am writing the following code to find out the required strings are present
I got tired of writing the following code: /* Commenting out irrelevant parts public
I have the following code for writing draw calls to a back buffer canvas,
I'm writing an XML file with the following code: Source source = new DOMSource(rootElement);
Mono won't fire the following code: I get internal server error 500, error writing
How I'm stuck with writing a test for the following code. I want to
does any one know if, for example, I'm writing in c++ the following code:
I have the following section of code in an app that I am writing:

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.