A string view is a non-owning reference to a string. It represents a view of a sequence of characters. This sequence of characters can be a C++ string or a C-string. A string view needs the header
🔑 A string view is a for copying optimized string
From a birds-eye perspective the purpose of
std::string_viewis to avoid copying data that is already owned by someone else and to allow immutable access to a
std::stringlike object. The string view is a kind of a restricted string that supports only immutable operations. Additionally, a string view
svhas two additional mutating operations:
String views are class templates parameterized by their character and their character trait. The character trait has a default. In contrast to a string, a string view is non-owner and, therefore, needs no allocator.