我使用fstream并使用getenv来获取appdata的路径。我使用了以下代码,但它在appdata / roaming /上输出
QString appdata = getenv(“appdata”);appdata + =“\ DoDLog.log”;fstream stud;…
你需要使用 SHGetSpecialFolderLocation
这是一个C解决方案,它应该不难适应C ++, QString , std::string 管他呢。
QString
std::string
#include <shlobj.h> ... HRESULT GetFolderLocation (int csidl, char* buffer) { LPITEMIDLIST pidl = 0; HRESULT result = SHGetSpecialFolderLocation(NULL, csidl, &pidl); *buffer = 0 ; if (result == 0) { SHGetPathFromIDList(pidl, buffer); CoTaskMemFree(pidl); } return result; } ... char str[_MAX_PATH]; GetFolderLocation(CSIDL_LOCAL_APPDATA, str); // now str contains "C:\Users\<user>\AppData\Local" ...