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

The Archive Base Latest Questions

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

I do want to give a default value for the positional parameter as in

  • 0

I do want to give a default value for the positional parameter as in the comment in the code, but the compiler complains. The code as it is compiles fine. I use boost 1.46.1 and g++

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

    po::positional_options_description p;
    p.add("path", -1);

    po::options_description desc("Options");
    std::vector<std::string> vec_str;
    std::string str;
    desc.add_options()
        ("foo,f", po::value< std::string >()->default_value(str), "bar")
        //("path,p", po::value< std::vector<std::string> >()->default_value(vec_str), "input files.")
        ("path,p", po::value< std::vector<std::string> >(), "input files.")
    ;

    po::variables_map vm;
    po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
    po::notify(vm);
}
  • 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-09T15:04:35+00:00Added an answer on June 9, 2026 at 3:04 pm

    I need to give a textual representation of the default value, see http://lists.boost.org/boost-users/2010/01/55054.php.

    I.e. the following line works:

     ("path,p", po::value< std::vector<std::string> > ()->default_value(std::vector<std::string>(), ""), "input files.")
    

    I guess this is needed for the help output, which could in my example

    std::cout << desc << std::endl;
    

    Since the compiler doesn’t know how to overload the operator<<() for vector<string>, it complains.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to give default value to a textarea. The code is something like
I want to give the name of MainWindow.xib file in plist file through code,
I want to give a user access to a stored procedure, but not to
Possible Duplicate: How do you give a C# Auto-Property a default value? Hi all:
How do you give a C# Auto-Property a default value, using a custom attribute?
Possible Duplicate: How do you give a C# Auto-Property a default value? Is there
I need to give an automatically constructed method positional and default parameters. If I
Possible Duplicate: How do you give a C# Auto-Property a default value? I have
i want to insert default value in database table and i am using and
The code I want to work: <Extension()> Public Function NValue(Of T)(ByVal value As Nullable(Of

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.