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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:05:51+00:00 2026-05-23T06:05:51+00:00

I’ve asked in one of my posts a question about alternative to boost::lexical_cast and

  • 0

I’ve asked in one of my posts a question about alternative to boost::lexical_cast and amongst many replies I’ve got one suggestion stoi as a viable alternative.
I’ve decided to test it and to my surprise as a second argument to this function (argument describing size) is a pointer to size_t type, not actual size_t type. Is there any logical explanation for that and in what way it is better to have a pointer to actual object than object itself (just in this particular case when size is concerned and I wouldn’t instinctively assign size with pointer)?

Link to stoi doc: http://msdn.microsoft.com/en-us/library/ee404860.aspx

  • 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-23T06:05:52+00:00Added an answer on May 23, 2026 at 6:05 am

    That is a way of having optional arguments. Basically, if you are interested in knowing which is the first character that was not converted into the number. If you are not really interested in that result, you can pass nullptr.

    §21.5 [string.conversions]/1 […] If the function does not throw an exception and idx != 0, the function stores in *idx the index of the first unconverted element of str.

    This is meant to be used as:

    int main() {
       std::string two{"2 and more contents"};
       // I don't care, just want a number:
       int i = std::stoi( two, 0, 10 );            // base = 0
    
       std::size_t first_not_converted;
       int i = std::stoi( two, &first_not_converted, 10 );
    
       std::cout << "Unconverted string is: " << two.substr( first_not_converted ) << std::endl;
    }
    

    By using a pointer you can make the argument really optional, if it was an out parameter, but required a reference would be used, but that would require user code to create the variable always regardless of whether they are interested in the value or not, so it would not be really optional.

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

Sidebar

Related Questions

I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I have a bunch of posts stored in text files formatted in yaml/textile (from

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.