Earlier quoted context omitted.
It's still quite easy to shoot oneself in the foot with modern C++: #include #include #include int main() { std::string_view v = std::string("xyz"); std::cout
OK i'll bite. What's wrong with this? It functions as expected or am I missing something. Edit: NVM, for those wondering the std::string constructor copies the string when it doesnt have to. But the solution here is to just initialize the string_view with the char data instead of the std::string instance Edit: Ignore me see below
You have a temporary std::string, pointed to by a string_view, which means that it's freed, and the view is dangling, and then used when printing things out.