I've been playing around with the std::string_view
library and I have been contemplating on changing a code base I have been working on to use std::string_view
as much as possible. However, in many of the threads that I have read on the subject of when and where to use std::string_view
instead of const std::string &
. I have seen many answers say, "When you don't need a null terminated string." So as I began searching around the web for, "when do you need a null terminated string?" I haven't really come across any helpful answers on the subject.
I can think of an example of an external library that you will link to that requires a std::string
. And in that case you would need a null terminated string since that library requires it. I guess another example would be if you need to modify the string itself, but then we wouldn't pass it by const &
if we needed to modify it.
So when would you need to use a null terminated string?
Links that I have looked at: