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 3228294
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:40:31+00:00 2026-05-17T16:40:31+00:00

Consider the following trivial program adopted from the boost program options examples #include <boost/program_options.hpp>

  • 0

Consider the following trivial program adopted from the boost program options examples

#include <boost/program_options.hpp>
#include <boost/version.hpp>

#include <iostream>

int
main( int argc, char** argv )
{
    namespace po = boost::program_options;

    po::options_description desc("Options");

    unsigned foo;
    desc.add_options()
        ("help,h", "produce help message")
        ("foo", po::value(&foo), "set foo") 
        ;

    po::variables_map vm;
    try {
        po::store(
                po::parse_command_line( argc, argv, desc ),
                vm
                );
        po::notify( vm );

        if ( vm.count("help") ) {
            std::cout << desc << "\n";
            std::cout << "boost version: " << BOOST_LIB_VERSION << std::endl;
        }
    } catch ( const boost::program_options::error& e ) {
        std::cerr << e.what() << std::endl;
    }
}

the following behavior is as expected:

samm$ ./a.out -h
Options:
  -h [ --help ]         produce help message
  --foo arg             set foo

boost version: 1_44
samm$ ./a.out --help
Options:
  -h [ --help ]         produce help message
  --foo arg             set foo

boost version: 1_44
samm$ ./a.out --foo 1
samm$ ./a.out --asdf
unknown option asdf
samm$

However, I was surprised when introducing a positional argument, it was not flagged as an error

samm$ ./a.out foo bar baz
samm$

Why is boost::program_options::too_many_positional_options_error exception not thrown?

  • 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-05-17T16:40:31+00:00Added an answer on May 17, 2026 at 4:40 pm

    when I explicitly indicate no positional options are supported:

        const po::positional_options_description p; // note empty positional options
        po::store(
                po::command_line_parser( argc, argv).
                          options( desc ).
                          positional( p ).
                          run(),
                          vm
                          );
    

    I get the expected behavior:

    samm$ ./a.out asdf foo bar
    too many positional options
    samm$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider following example. #include <iostream> #include <algorithm> #include <vector> #include <boost/bind.hpp> void func(int e,
Consider following example. #include <iostream> #include <boost/optional.hpp> template < typename A > int boo(
Consider following example: #include <iostream> #include <functional> #include <algorithm> #include <vector> #include <boost/bind.hpp> const
Consider following program: static void Main (string[] args) { int i; uint ui; i
Consider following code: main.cpp: #include <iostream> typedef void ( * fncptr)(void); extern void externalfunc(void);
Consider following source files 1.cpp #include <iostream> using namespace std; struct X { X()
Consider following example: #include <stdlib.h> #include <stdio.h> #include <errno.h> #include <hiredis/hiredis.h> int main(int argc,
Consider following codes: #include <stdio.h> #include <malloc.h> void allocateMatrix(int **m, int l, int c)
Consider following case: #include<stdio.h> int main() { char A[5]; scanf(%s,A); printf(%s,A); } My question
Consider following tables: How to skip and take groups from the table? Tried using

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.