The Basics
Let's begin our study on std::string_view with a simple use case.
We'll cover the following...
We'll cover the following...
Introductory Example
Let’s try a little experiment:
How many string copies are created in the below example?
Can you count them all?
The answer is 3 or 5 depending on the compiler, but usually, it should be 3.
- The first one is for
str. - The second one is for the second argument in
StartFromWordStr- the argument isconst string&so since we passconst char*it will create a new string. - The third one comes from
substr