© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2023
S. DmitrovićModern C++ for Absolute Beginnershttps://doi.org/10.1007/978-1-4842-9274-7_13

13. Introduction to Strings

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

We can store these string literals inside a std::string type. The 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.

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 = ...

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