CHAPTER 8

image

String

The stringclass in C++ is used to store string values. Before a string can be declared the string header must first be included. The standard namespace can also be included since the string class is part of that namespace.

#include <string>using namespace std;

Strings can then be declared like any other data type. To assign a string value to a string variable, delimit the literals by double quotes and assign them to the variable. The initial value can also be assigned through constructor initialization at the same time as the string is declared.

string h = "Hello";string w (" World");

String Combining

The plus sign, known as ...

Get C++ 14 Quick Syntax Reference, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.