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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:35:06+00:00 2026-06-12T07:35:06+00:00

The first parameter of C++ STL function substr(pos,n), pos, is said to have this

  • 0

The first parameter of C++ STL function substr(pos,n), pos, is said to have this behaviour.

“If the position passed is past the end of the string, an out_of_range exception is thrown.”

However, if I do something like

string s("ab");
cout<<s.substr(2,666)<<endl;

then no exception is thrown even though the pos=2 is by definition past the end of the string.

The string::end defines the position “after the last character in the string” as “past the end of the string.”
I noticed the returned character is always the ‘\0’. My question is if this is standard behaviour and if I can count on the fact that an empty string is returned in this case. Thank you.

  • 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-12T07:35:08+00:00Added an answer on June 12, 2026 at 7:35 am

    The actual requirement is (§21.4.7.8):

    1 Requires: pos <= size()
    2 Throws: out_of_range if pos > size().
    

    In your case, pos == size(), so you should never see an exception, and should always get an empty string.

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

Sidebar

Related Questions

If I have a function which accepts more than one string parameter, the first
I have two arrays the first one has this structure Parameter Keys array array
I have a c function that is called from lua. The first parameter is
I created a function for crypting passwords. But the first parameter is not passed
that required in first parameter of FindWindow function? there long time,I seen this information
In this code I am trying to have the first parameter in my worker
EventDispatcher.addEventListener() expects first parameter for event type (parameter of String type). But the current
Via Function: myfunc Parameters: a - First parameter b - First parameter I can
I'm trying to do something like this http://myweb.com//page If first parameter is not present
I came across this in the book: wscanf(L%lf, &variable); where the first parameter is

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.