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++?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
The character array is still in there, it just has a class wrapped around it. Imagine something like 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:
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.