Tsallaka zuwa abun ciki
Justice Tech School

string_view

string_view looks at text without copying it. Do not keep it past the lifetime of the text.

Example
#include <iostream>
#include <string_view>

int main() {
  std::string_view sv = "hello world";
  std::cout << sv.substr(0, 5) << " " << sv.size() << "\n";
  return 0;
}

Result

hello 11

Exercise

Non owning view.

std:: sv

Quiz Test

Does string_view copy text?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.