Please note, this is a STATIC archive of website www.w3schools.com from 05 May 2020, cach3.com does not collect or store any user information, there is no "phishing" involved.
THE WORLD'S LARGEST WEB DEVELOPER SITE

C++ Strings


C++ Strings

Strings are used for storing text.

A string variable contains a collection of characters surrounded by double quotes:

Example

Create a variable of type string and assign it a value:

string greeting = "Hello";

To use strings, you must include an additional header file in the source code, the <string> library:

Example

// Include the string library
#include <string>

// Create a string variable
string greeting = "Hello";
Run example »

C++ Exercises

Test Yourself With Exercises

Exercise:

Fill in the missing part to create a greeting variable of type string and assign it the value Hello.

  = ;

Start the Exercise