开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜