Boost Filesystem 在 Linux 上创建目录替换“/”与“\”
在以下示例中使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来由于某种原因 boost::filesystem 认为您在 Windows 上,而不是 Linux 上,因此使用 Windows 样式的路径名(用 \ 分隔)。您能否发布更多有关如何构建 Boost 以及如何包含标头的信息?您是否正在 Linux 上构建 Windows 版本的 Boost?
编辑:我已尝试将自己设置为尽可能接近您的配置。 Ubuntu 9.10,安装了 libboost1.40-all-dev。当我编译并运行以下程序时,它按预期工作,在
/data
中创建一个名为configSet
的目录。您可以尝试使用以下命令编译并运行该程序,看看它是否会给出不同的结果?
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
.Can you try compiling and running that program, with the following commands, and see if it gives you different results?