c++ 查找主操作系统目录

标签 c++ linux windows max

我正在尝试使用 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/

相关文章:

c - 简单的 C 程序在 Windows 上崩溃

c++ - 定时器超时复位

c++ - 编译 CUDA 示例出现构建错误

c++ - 解析字节数组中的 Unicode

linux - 如何在 Linux 机器上配置 java?

c++ - 如果我过早获得窗口句柄,控制台窗口会出现问题……?

Windows PE确定入口点虚拟地址

c++ - 对成员模板函数的访问控制

linux - 使用 bash 文件替换字符串

c - 如何使用 v4l2 linux 界面从网络摄像头获取视频?