Reputation: 1939
I'd like to find the directory of the current user profile programmatically in C++.
Upvotes: 5
Views: 5111
Reputation: 41
Simplest way on Windows & Linux:
char *szBuff;
szBuff=std::getenv("USERPROFILE"); //Returning value of %USERPROFILE%
Upvotes: 4
Reputation: 8018
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.
Upvotes: 2
Reputation: 36026
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
Upvotes: 10