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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:41:02+00:00 2026-06-01T07:41:02+00:00

I have a program that’s expected to take as input a few options to

  • 0

I have a program that’s expected to take as input a few options to specify probabilities in the form (p1, p2, p3, … ). So the command line usage would literally be:

./myprog -dist (0.20, 0.40, 0.40)

I want to parse lists like this in C++ and I am currently trying to do it with iterators for the std::string type and the split function provided by Boost.

// Assume stuff up here is OK
std::vector<string> dist_strs; // Will hold the stuff that is split by boost.
std::string tmp1(argv[k+1]);   // Assign the parentheses enclosed list into this std::string.

// Do some error checking here to make sure tmp1 is valid.

boost::split(dist_strs,  <what to put here?>   , boost::is_any_of(", "));

Note above the <what to put here?> part. Since I need to ignore the beginning and ending parentheses, I want to do something like

tmp1.substr( ++tmp1.begin(), --tmp1.end() )

but it doesn’t look like substr works this way, and I cannot find a function in the documentation that works to do this.

One idea I had was to do iterator arithmetic, if this is permitted, and use substr to call

tmp1.substr( ++tmp1.begin(), (--tmp1.end()) - (++tmp1.begin()) )

but I wasn’t sure if this is allowed, or if it is a reasonable way to do it. If this isn’t a valid approach, what is a better one? …Many thanks in advance.

  • 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-01T07:41:03+00:00Added an answer on June 1, 2026 at 7:41 am

    std::string‘s constructor should provide the functionality you need.

    std::string(tmp1.begin() + 1, tmp1.end() - 1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that places input buttons on a form. When a user
I have a program that wants to be called from the command line many
I have a program that passes command-line arguments to an associated file (i.e. associated
I have a program that takes the counts of experiments as command string argument
I have a program that embeds Lua and implements a form of lazy function
I have program that has a variable that should never change. However, somehow, it
I have program that runs fast enough. I want to see the number of
I have a program that spits out both standard error and standard out, and
I have a program that creates a Windows user account using the NetUserAdd() API
I have a program that uses the mt19937 random number generator from boost::random. I

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.