I would like to find the directory of the current user profile programmatically in C ++.
SHGetSpecialFolderLocation is the best way to access most special paths on Windows. Passed CSIDL_PROFILEit should get the folder you are interested in.
CSIDL_PROFILE
If you're really interested in the contents of the% UserProfile% variable, you can try ExpandEnvironmentStrings
The easiest way for Windows and Linux:
char *szBuff; szBuff=std::getenv("USERPROFILE"); //Returning value of %USERPROFILE%
Windows Vista , SHGetKnownFolderPath. - .