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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:58:18+00:00 2026-05-24T01:58:18+00:00

How was the string type created in C++? In C, strings are character arrays,

  • 0

How was the “string” type created in C++? In C, strings are character arrays, but how did C++ turn the character arrays into the “strings” we know of in C++?

  • 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-24T01:58:19+00:00Added an answer on May 24, 2026 at 1:58 am

    The character array is still in there, it just has a class wrapped around it. Imagine something like this:

    class String
    {
    private:
      char* stringData;
    
    public:
      String(const char* str)
      {
        stringData = new char[strlen(str)+1];
        strcpy(stringData, str);
      }
    
      ~String() { delete[] stringData; }
    
      String& operator += (const String& rhs)
      {
        char* newStringData = new char[strlen(rhs) + strlen(stringData) + 1];
        strcpy(newStringData, stringData);
        strcpy(newStringData + strlen(stringData), rhs);
        delete[] stringData;
        stringData = newStringData;
        return *this;
      }
    };
    

    That’s obviously a very incomplete example, but you get the idea, right?

    The actual implementation of std::string is pretty comprehensive, but it’s nothing you couldn’t do yourself. Here’s some differences in the official std::string class from what I posted:

    • The length of the string is usually included as a member variable, so you don’t have to keep calling strlen to find the length.
    • The std::string class uses templates, so you’re not limited to the char type. If you’re using Unicode, you can use std::wstring, which uses 16- or 32- bit strings by replacing the char type with the wchar_t type.
    • Usually there’s lots of optimizations to choose from. Lately the most popular has been the “short string” optimization.

    Once you’ve relatively comfortable with C++, you should try writing your own string class. It’s not something you would use in practice, but it’s a really good exercise for library writing.

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

Sidebar

Related Questions

C++: Using and returning character arrays from functions, return type or reference? I'm trying
I'm trying to create a dictionary type - ie hash table with a string
how to convert a String type to a Int i have a tuple and
Delphi 2009 has changed its string type to use 2 bytes to represent a
how to read my blob column from mysql to string type in hibernate I
hi from my db i am getting a value as string type and when
the Text property of control on winform is always string type, so if i
I'm trying to read a file line by line to a string type variable
I have a bean of type string[] which has two or more values. I
I need to convert from a SQLVARCHAR to a string data type Variable definitions

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.