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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:18:53+00:00 2026-05-26T22:18:53+00:00

The two overloaded function in std::string got my attention: string& append(const string& str, size_t

  • 0

The two overloaded function in std::string got my attention:

string& append(const string& str, size_t pos, size_t n);
string& append(const char* s, size_t n);

I’m curious that why the char* version of string::append() doesn’t provide an additional parameter size_t pos, as the one below:

string& append(const char* s, size_t pos, size_t n);

For the other two functions, the situation is also the same:

int compare(size_t pos1, size_t n1, const string& str, size_t pos2, size_t n2) const;
int compare(size_t pos1, size_t n1, const char* s, size_t n2) const;

string& replace(size_t pos1, size_t n1, const string& str, size_t pos2, size_t n2);
string& replace(size_t pos1, size_t n1, const char* s, size_t n2);

The char* version of these functions lack the parameter size_t pos2, which is not as flexible as their string& counterpart. My question is the following:

  1. Why does std::string design its interface like this?
  2. Why doesn’t the char* version function has size_t pos as well?
  3. What’s the consideration(s) behind this?

Thank you for reading!

  • 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-26T22:18:54+00:00Added an answer on May 26, 2026 at 10:18 pm

    Because you can just add pos to s:

    str.append(ptr + pos, len);
    

    That isn’t to say it wouldn’t be a nice shorthand to have, but they (generally) only want to minimally add the necessary functions, not the trivial wrapper kind.

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

Sidebar

Related Questions

I have two overloaded methods, one with an optional parameter. void foo(string a) {
I define two versions of overloaded operator[] function in a class array . ptr
In situations where two interfaces apply to an object, and there are two overloaded
MessageBox.Show((some_string.Length).ToString); I am getting two errors for this: The best overloaded method match for
I would like to call a member through lambda::bind. Unfortunately I have got two
Environment: VS2005 C++ using STLPort 5.1.4. Compiling the following code snippet: std::string copied =
I have two questions related to function objects and function pointers, Question : 1
It just occurred to me I noticed that std::string 's substr operation could be
I'm trying to understand how to select the right overloaded function template at compile-time
Since C+++ allows function overloading, can we overload main() ? For example, int main(const

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.