我正在尝试使用 C++ 在操作系统的主目录中创建文件(例如我的“c”盘中的 Windows)。 有没有比遍历所有磁盘并搜索“Windows”文件夹更好的方法?它在 mac 和 linux 中也类似吗?
最佳答案
在 Windows 中,您可以调用 GetWindowsDirectory
函数 (link)。在 Linux 和 Mac 中(我认为),没有主系统目录这样的东西。
但是,正如 David 指出的那样,您不应该将任何文件放在那里:
This function is provided primarily for compatibility with legacy applications. New applications should store code in the Program Files folder and persistent data in the Application Data folder in the user's profile. For more information, see ShGetFolderPath.
关于c++ 查找主操作系统目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18934096/