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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:44:03+00:00 2026-05-26T10:44:03+00:00

I use boost.program_options library. Consider this simplified case. po::options_description desc(Usage); desc.add_options() (uninstall,u, uninstall program)

  • 0

I use boost.program_options library. Consider this simplified case.

po::options_description desc("Usage");
desc.add_options()
("uninstall,u", "uninstall program")
("custom,c", po::wvalue<std::wstring>(), "specify custom action");

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

I want to produce error on such command-line:

testprog.exe -u c- action1

Note, user made a typo “c-” instead of “-c”. But the parser understands this as a single -u option. How do I handle such cases?

  • 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-26T10:44:04+00:00Added an answer on May 26, 2026 at 10:44 am

    I want to produce error on such command-line:

    testprog.exe -u c- action1
    

    Note, user made a typo “c-” instead of “-c”. But the parser
    understands this as a single -u option. How do I handle such cases?

    Instruct the program_options library to accept no positional arguments and you get the desired behavior

    code & compile:

    macmini:stackoverflow samm$ cat po.cc
    #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("Usage");
        desc.add_options()
            ("uninstall,u", "uninstall program")
            ("custom,c", po::wvalue<std::wstring>(), "specify custom action")
            ;
    
        po::variables_map vm;
        po::command_line_parser cmd_line( argc, argv );
        cmd_line.options( desc );
        cmd_line.positional( po::positional_options_description() );
    
        try {
            po::store( cmd_line.run(), vm );
    
            po::notify(vm);
        } catch ( const std::exception& e ) {
            std::cerr << e.what() << std::endl;
            return -1;
        }
    
        return 0;
    }
    macmini:stackoverflow samm$ g++ po.cc -I /opt/local/include -L/opt/local/lib -lboost_program_options -Wl,-rpath,/opt/local/lib
    

    run:

    macmini:stackoverflow samm$ ./a.out -u c- action1
    too many positional options
    macmini:stackoverflow samm$ ./a.out -u -c action1
    macmini:stackoverflow samm$ 
    
    • 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 am currently writing a CUDA application and want to use the boost::program_options library
I wanted to use boost::thread in my program, but get the following compiler error
So I am wanting to use boost signals in my C++ program. I add:
I am tring to use back-reference in boost version 1.44 but this don't work
I am trying to use the boost generic image library to convert CYMK images
I'm trying to use the boost threads, but when running the program i get
i'm trying to use boost regex within my program the problem is i get
I wrote a c++ program using boost library in Xcode. Here is my code.
I have a program where I use boost::threads for multi threading. Unfortunately drd (

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.