Hi!~ I made this stupid little app that is basically an "anti fetch" for linux systems, but I'm having trouble with the difference above, i was using std::string_view for stuf like los::get_hostname() but it kept throwing random bytes at me, am I programming wrong? I don't know wether i should try to fix that or remain with std::string, all feedback is appreciated.
#Use of std::string vs const std::string& and std::string_view
15 messages · Page 1 of 1 (latest)
https://github.com/EveMeows/los/blob/main/los/release.cpp#L13
i was also using string_view for oname and vname
but it kept throwing random bytes too...
am i misunderstanding what std::string_view is?
std::string_view is a nonowning reference to a std::string (or to some other string-like object). it cannot extend the lifetime of the object it is referencing, and i suspect what you're doing here is trying to do that
might help to know that a string view is just a pointer and a length
it's useful as a generic interface for people that have a string object that isn't necessarily std::string
it's only purpose is to point at some characters in memory
OHHHHH okay
so if the string its pointing to dies
it dies with it
thats why i was getting random bytes