Search⌘ K
AI Features

Handling Non-Null Terminated Strings

Understand how std::string_view works with non null terminated strings and the challenges that arise when interfacing with APIs that require null terminated strings. Explore practical examples to handle these cases effectively and improve your string management skills in C++17.

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:

C++ 17
#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. ...