How to resolve location of %UserProfile% programmatically in C++?
I'd like to find the directory of the curre开发者_如何学编程nt user profile programmatically in C++.
SHGetSpecialFolderLocation is the best way to get at most of the special paths on Windows. Passed CSIDL_PROFILE
it should retrieve the folder you are interested in.
If you are actually interested in the contents of the %UserProfile% environment variable you could try ExpandEnvironmentStrings
Simplest way on Windows & Linux:
char *szBuff;
szBuff=std::getenv("USERPROFILE"); //Returning value of %USERPROFILE%
To cover all user profile scenarios in Windows Vista and up there is SHGetKnownFolderPath. Here is the link to the docs page on it and related functions.
精彩评论