© Mikael Olsson 2020
M. OlssonC++20 Quick Syntax Referencehttps://doi.org/10.1007/978-1-4842-5995-5_8

8. Strings

Mikael Olsson1 
(1)
Hammarland, Finland
 
The string class in C++ is used to store string values. Before a string can be declared, the string header must be included. The standard namespace can also be used 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 either direct or uniform initialization at the same time as the string is declared.
string h = "Hello";
string w ("Hi"); // direct initialization ...

Get C++20 Quick Syntax Reference: A Pocket Guide to the Language, APIs, and Library 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.