Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22024

Remove last character of std::string_view

$
0
0

I'm trying to remove the last character of an std string view, but no matter what I do it remains there. I think its because I'm accidentally removing the "/0" instead of the desired "]".

Here is my code:

#include <iostream>#include <tstr/tstring.h>#include <cstring>template<typename Class>constexpr const char* to_string() {    std::string_view str = __PRETTY_FUNCTION__;    auto first = str.find("= ");    auto last = str.find("]");    auto str2 = str.substr(first + 2, last - first + 1);    return str2.data();}class Foo {};int main(){    std::cout << to_string<Foo>() << std::endl;    return 0;}

This outputs Foo]. How can I remove the prepending ] ?

Thanks.


Viewing all articles
Browse latest Browse all 22024

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>