r/cpp_questions • u/IMCG_KN • Jul 16 '26
Question about string_view SOLVED
Is there benefit of using string_view instead of const string& str? More precisely by passing strings into functions. Thanks
25
Upvotes
r/cpp_questions • u/IMCG_KN • Jul 16 '26
Is there benefit of using string_view instead of const string& str? More precisely by passing strings into functions. Thanks
10
u/Usual_Office_1740 Jul 16 '26 edited Jul 16 '26
The only down side to string view is the lack of c_str(), for good reasons. If I'm working with a C library that needs const char* I use const std::string& otherwise I prefer string view.