error: 'string_view' is not a member of 'std'
I'm using gcc compiler for visual studio code. In C++17, gcc has made some changed, including integrating string_view and string together. I think that it seem more complicated now,as string will implicitly convert to string_view, in some case.
For more detail:http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0254r2.pdf
I didn't find any bug in your code. I compiled your code here (Copy your code there and select the language C++17 before compiling) and it is working as expected. Just check the compiler which you are running supports C++17 features. Because std::string_view is only available from C++17 onwards. To enable C++17 in Visual studio check here and in Visual studio code follow this .
Hope this will help you.