Boost Filesystem createdirectories on Linux replacing "/" with "\"
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开发者_如何学JAVA executed on a Windows system. I am currently testing on Linux using Ubuntu 9.10
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
精彩评论