std::string_view Creation

The different ways of initializing a string_view are listed in this lesson.

You can create a string_view in several ways:

  • from const char* - providing a pointer to a null-terminated string
  • from const char* with length
  • by using a conversion from std::string
  • by using ""sv literal

Here’s an example of various creation options:

Get hands-on with 1400+ tech skills courses.