In C++, std::string::subview() returns a std::string_view that refers to a slice of the string without copying (C++26).
If your compiler lacks subview, build a view with std::string_view(s).substr(pos, len) or std::string_view(s.data() + pos, len). Include <string>.
This is a member of std::string. A string grows as you append, stores characters contiguously, and can reallocate—after growth, old iterators and references may be invalid. Prefer at() when you want bounds checks; remember find returns npos when missing.
Syntax
Pass position and optional length (C++26).
C++
std::string_view v = s.subview(2, 3);
Call
What it does
s.subview(pos)
View from pos to the end.
s.subview(pos, len)
View of up to len characters.
This tutorial documents the C++26 direction. Examples below also show the portable string_view approach so you can practice today.