Thank you. Might be able to use that in another project, but can't for this one.
I have to get the windows User profile directory as "base" and add the relative path from there, because i move the project between different machines during development.
That's why i grab the USERPROFILE enviroment variable, and my question was if the way i do that, is the "correct" way. Your answer tells med, that i have too much "C baggage" with me. ;)
But i can't seem to find any safe C++ way of getting the env variable. So my question is actually if there is a better way to grab that USERPROFILE env. var than resorting to C ;)
Ah, I see.
Most of the windows code is still using C strings, unfortunately.
there is
GetEnvironmentVariable
getenv
and probably others.
I would thing
string s{genenv("variable")};
might work. string is overloaded to construct from C strings, so after the one call its back to OOP.
My main goal here would be getting rid of any hands on dynamic memory, even the smart pointer. It feels excessive if it can be avoided.
So my original piece of code is still an ok way to do it in C++? (I am checking if a nullptr is returned, and i changed from getenv to _dupenv_s as my compiler suggested.)
Was just hoping there were a nicer way as the original code is a bit "clunky". ;)