...

/

Handling Non-Null Terminated Strings

Handling Non-Null Terminated Strings

A string_view works well with null-terminated strings. Let's see what happens when we point it to a substring which does not have a null character at the end.

We'll cover the following...

If you get a string_view from a string then it will point to a null-terminated chunk of memory:

Press + to interact
#include <iostream>
#include <string>
using namespace std;
int main() {
std::string s = "Hello World";
std::cout << s.size() << '\n';
std::string_view sv = s;
std::cout << sv.size() << '\n';
}

The two cout statements will both print 11. ...