Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


What is a C++ string?

Educative Answers Team

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

A string in C++ is an ordered sequence of characters.

There are three possible ways to create a sequence of characters in C++, a ‘string’ is just one of these ways:

  1. A simple array of characters is just like any other array; but it has no special properties that other arrays may have.
svg viewer
svg viewer

  1. A null terminated string, also called a C-string, consists of an array of characters terminated by the null character ‘\0’. Strings of these forms can be created and dealt with using <cstring> library. Note that the null character may not be the last character in the C-string array.

  1. A C++ string is an object that is a part of the C++ standard library. It is an instance of a “class” data type, used for convenient manipulation of sequences of characters. To use the string class in your program, the <string> header must be included. The standard library string class can be accessed through the std namespace.