If you want to reuse memory in C++, you'll either have to modify the string or return a string_view because strings must be null terminated (string_views are not). If you just chop off the last n-bytes of a string, it won't be a string anymore.
I personally use std::string_view as much as possible especially for compile-time constants. Then you can slice as much as you want without reallocating.
I personally use std::string_view as much as possible especially for compile-time constants. Then you can slice as much as you want without reallocating.