c++ - mkdir Windows 与 Linux

标签 c++ windows linux mkdir

我在将 Linux 工具移植到 Windows 时遇到问题。我在 Windows 系统上使用 MinGW。我有一个处理所有输入/输出的类,其中包括这一行:

mkdir(strPath.c_str(), 0777); // works on Linux but not on Windows and when it is changed to
_mkdir(strPath.c_str()); // it works on Windows but not on Linux

任何想法我可以做什么,以便它在两个系统上都适用?

最佳答案

#if defined(_WIN32)
_mkdir(strPath.c_str());
#else 
mkdir(strPath.c_str(), 0777); // notice that 777 is different than 0777
#endif

关于c++ - mkdir Windows 与 Linux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10356712/

相关文章:

c++ - 有没有办法在 C++ 中同时为多个模板分配一个类型?

c++ - UDP 套接字 : recvfrom and receive address

c++ - BOOST ASIO - 如何编写控制台服务器

linux - Bison 示例代码未编译

linux - Bash 从 TSV 文件中提取特定列到新文件,并添加带有提取列标题的额外列

c++ - 捕获多个参数

windows - 为什么我的 Qt 应用程序即使在非管理员访问权限下也会写入 protected 位置?

windows - 为什么 Textpad 会询问您是否要使用 POSIX 正则表达式语法?

windows - 在没有 GUI 或 msi 安装程序的情况下手动创建 msix 包

c++ - 如何编辑默认的 makefile