Boost.Filesystem create_directories修改目录名称 [英] Boost.Filesystem create_directories mangles directory name
问题描述
我正在尝试使用Boost.Filesystem创建目录(该目录可以由用户提供,因此它可能是带有嵌套目录的路径;该路径中的所有目录,部分目录或不存在目录都可以启动) ).当我运行程序时,会创建一个目录,但这不是我想要的;包含路径的字符串似乎被弄乱了.我从未两次得到相同的结果,但是目录的名称始终以冒号开头.
I am trying to make a directory using Boost.Filesystem (the directory can be provided by the user, so it may be a path with nested directories; all, some, or none of the directories in that path may exist to start). When I run the program, a directory is created, but it is not what I asked for; the string containing the path appears to be getting mangled. I never get the same result twice, but the name of the directory always starts with a colon.
一个最小的例子:
#include <iostream>
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
int main(int argc, char* argv[]) {
fs::path path = "junk/morejunk";
if (!fs::create_directories(path)) {
std::cerr << "Failed to create directory " << path << ".\n";
}
return(0);
}
运行该命令,我会得到诸如:@K%C5?
,:%C0)%E0?
和:%C0%E9%93?
的目录.
Running that, I get directories such as :@K%C5?
, :%C0)%E0?
, and :%C0%E9%93?
.
我在使Boost正确链接时遇到了一些麻烦,但是上面的程序现在可以编译并运行.如果有必要,请提供一些信息:
-我正在使用Mac(OSX 10.9.4)
-MacPorts上同时安装了GCC和Boost(使用+ gcc49选项进行增强)
-GCC版本4.9.2_1
-Boost版本1.57.0_1
-我的Makefile看起来像
I had some trouble getting Boost to link correctly, but the above program compiles and runs now. In case it's necessary, some information:
-- I'm using a Mac (OSX 10.9.4)
-- GCC and Boost both installed with MacPorts (Boost with the +gcc49 option)
-- GCC version 4.9.2_1
-- Boost version 1.57.0_1
-- my Makefile looks like
CC = /opt/local/bin/g++
FLAGS = -I/opt/local/include -L/opt/local/lib -lboost_system-mt -lboost_filesystem-mt
driver : driver.cpp
$(CC) $(FLAGS) -o driver driver.cpp
欢迎任何建议;自从我大量使用C ++以来已经有一段时间了,而且我对Boost的使用还不是很丰富.
Any suggestions welcome; it's been a while since I've used C++ much, and I'm not very experienced with Boost.
推荐答案
请确保将文件另存为ASCII,latin1或UTF8.
Out on a limb, make sure you save your file as ASCII, latin1 or UTF8.
否则,您可能会从不兼容的库版本中获得未定义的行为.
Otherwise you might have undefined behaviour from incompatible library versions.
您可以使用DYLD_LIBRARY_PATH
获取首选的Boost库(链接的库).另请参见
You could use DYLD_LIBRARY_PATH
to get the preferred libraries for boost (the ones which you link against). See also Is it OK to use DYLD_LIBRARY_PATH on Mac OS X? And, what's the dynamic library search algorithm with it?
这篇关于Boost.Filesystem create_directories修改目录名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!