From the course: C++ Best Practices for Developers

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Be careful with string_view

Be careful with string_view - C++ Tutorial

From the course: C++ Best Practices for Developers

Start my 1-month free trial

Be careful with string_view

- [Instructor] String_view is a non-owning reference to a string. It represents a view of a sequence of characters, either C++ strings or C strings. It is the non-owning part that can get you into trouble. The string views should not live longer than its source string. It also may not be NULL terminated, so us care when using it with C-style functions, like printf. But, it may offer a big performance boost, since it doesn't actually have to do much copying, it's just a reference to some screens, and that gives it a speed-up throughout the code.

Contents