© Slobodan Dmitrović 2020
S. DmitrovićModern C++ for Absolute Beginnershttps://doi.org/10.1007/978-1-4842-6047-0_13

13. Introduction to Strings

Slobodan Dmitrović1 
Belgrade, Serbia
Earlier, we mentioned printing out a string literal such as "Hello World ." to standard output via:
std::cout << "Hello World.";

We can store these literals inside std::string type. C++ standard library offers a compound type called string or rather std::string as it is part of the std namespace. We use it for storing and manipulating strings.

13.1 Defining a String

To use the std::string type, we need to include the <string> header in our program:
#include <string>
int main()
    std::string s = "Hello World.";
To print out this string on the standard output we use: ...

Get Modern C++ for Absolute Beginners: A Friendly Introduction to C++ Programming Language and C++11 to C++20 Standards 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.