The string data type

C++ is built on C, and it provides a data type that is defined in the namespace std and requires string as a header file.

C++ simplifies string manipulation in several ways. It even simplifies the declaration of a string over cstring so that there is no need to declare it as an array (it abstracts out that detail inside it).

Let’s practice how to use the string as a data type.

string variable: Declaration and printing

Here’s the code for declaring several kinds of simple initialization:

Get hands-on with 1200+ tech skills courses.