Create and initialise
As always, let's start by creating a string view.
You can create an empty string view. You can also create a string view from an existing string, an existing character-array, or an existing string view.
The table below gives you an overview of the various ways of creating a string view.
Methods | Example |
---|---|
Empty string view | std::string_view str_view |
From a C-string | std::string_view str_view2("C-string") |
From a string view | std::string_view str_view3(str_view2) |
From a C array | std::string_view str_view4(arr, sizeof arr) |
From a string_view | str_view4= str_view3.substring(2, 3) |
From a string view | std::string_view str_view5 = str_view4 |
Methods to create and set a string view
Get hands-on with 1400+ tech skills courses.