#include <Shlobj.h> #include <iostream> using namespace std; //獲取當前用戶AppData文件夾路徑 string GetLocalAppDataPath(){ char szDir[1024]; char szDoc[1024]; LPITEMIDLIST pidl = NULL; SHGetSpecialFolderLocation(NULL, CSIDL_LOCAL_APPDATA, &pidl); if (pidl && SHGetPathFromIDList(pidl, szDoc)){ GetShortPathName(szDoc, szDir, _MAX_PATH); } return szDir; } //獲取當前用戶 string GetLocalUserName(){ CHAR cUserNameBuffer[256]; DWORD dwUserNameSize=256; GetUserName(cUserNameBuffer, &dwUserNameSize); return cUserNameBuffer; } int main(){ string user = GetLocalUserName(); string path = "C:/Users/" + user + "/AppData/Roaming/BeyondCompare/BeyondCompare419.ini"; char *p = (char*)path.c_str(); if (remove(p) == 0){ cout << "刪除成功" << endl; } else{ cout << "刪除失敗" << endl; } system("pause"); return 0; }