Boost Filesystem 在 Linux 上创建目录替换“/”与“\”

发布于 2024-08-15 23:46:08 字数 380 浏览 3 评论 0原文

在以下示例中使用 Boost Filesystem 的 createdirectory(和 createdirectories)函数时,“/”将被替换为“\”。

boost::filesystem::path path ("/data/configSet");
boost::filesystem::create_directory(path);

这段代码被剪断后会生成一个名为“data\configSet”的目录,而不是在“data”内创建“configSet”的子目录。使用 createdirectories() 也会出现同样的问题;

在 Windows 系统上执行代码时不会出现此问题。我目前正在使用 Ubuntu 9.10 在 Linux 上进行测试

When using Boost Filesystem's createdirectory (and createdirectories) function in the following example, "/" is being replaced with "\".

boost::filesystem::path path ("/data/configSet");
boost::filesystem::create_directory(path);

This code snipped produces a directory called "data\configSet", instead of creating a subdirectory of "configSet" inside "data". The same problem occurs using createdirectories();

This issue does not occur when the code is executed on a Windows system. I am currently testing on Linux using Ubuntu 9.10

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安静被遗忘 2024-08-22 23:46:08

看起来由于某种原因 boost::filesystem 认为您在 Windows 上,而不是 Linux 上,因此使用 Windows 样式的路径名(用 \ 分隔)。您能否发布更多有关如何构建 Boost 以及如何包含标头的信息?您是否正在 Linux 上构建 Windows 版本的 Boost?

编辑:我已尝试将自己设置为尽可能接近您的配置。 Ubuntu 9.10,安装了 libboost1.40-all-dev。当我编译并运行以下程序时,它按预期工作,在 /data 中创建一个名为 configSet 的目录。

#include <boost/filesystem.hpp>

int main() {
  boost::filesystem::path p("/data/configSet");
  boost::filesystem::create_directory(p);

  return 0;
}

您可以尝试使用以下命令编译并运行该程序,看看它是否会给出不同的结果?

$ g++ -o boost-filesystem -lboost_filesystem boost-filesystem.cpp
$ ./boost-filesystem

It looks like for some reason boost::filesystem thinks that you are on Windows, not Linux, and thus is using Windows style pathnames (separated by \). Can you post a bit more information about how you are building Boost and how you're including the headers? Are you perhaps building a Windows version of Boost on Linux?

edit: I have tried setting myself up in a configuration as close to yours as possible. Ubuntu 9.10, libboost1.40-all-dev installed. When I compile and run the following program, it works as expected, creating a directory named configSet in /data.

#include <boost/filesystem.hpp>

int main() {
  boost::filesystem::path p("/data/configSet");
  boost::filesystem::create_directory(p);

  return 0;
}

Can you try compiling and running that program, with the following commands, and see if it gives you different results?

$ g++ -o boost-filesystem -lboost_filesystem boost-filesystem.cpp
$ ./boost-filesystem
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文