© Mikael Olsson 2018
Mikael OlssonC++17 Quick Syntax Referencehttps://doi.org/10.1007/978-1-4842-3600-0_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 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 ...

Get C++17 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.