Strings are used for storing text/characters.
For example, "Hello World" is a string.
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"; // Print the string cout << greeting;Note
Strings can contain multiple words, spaces, and punctuation:
Example
string greeting = "Hello and welcome!";
cout << greeting;