【发布时间】:2012-01-23 02:04:04
【问题描述】:
我正在尝试使用 Boost.Filesystem 库遍历目录。
问题是当我尝试实例化一个路径对象时,我得到一个 std::length_error 消息“字符串太长”,字符串长度不限,甚至例如“pippo”。
我已经尝试了所有这些:
string s = "pippo";
path p(s);
path p(s.begin(), s.end());
path p(s.c_str());
path p("pippo");
我在 windows 7 上使用 vc++10 的 boost 预编译版本 1.47。
提前谢谢你, 卢卡
编辑
这是执行的 boost 代码(path.hpp 第 129 行)
template <class Source>
path(Source const& source,
typename boost::enable_if<path_traits::is_pathable<
typename boost::decay<Source>::type> >::type* =0)
{
path_traits::dispatch(source, m_pathname, codecvt());
}
并且从(path_traits.hpp 第 174 行)抛出错误
template <class U> inline
void dispatch(const std::string& c, U& to, const codecvt_type& cvt)
{
if (c.size())
convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
}
抛出的函数是“转换”。从调试器中我看到了两个
&*c.begin()
和
&*c.begin() + c.size()
正确执行
【问题讨论】:
-
这是您正在运行的确切代码吗?
-
尝试在调试器中运行并告诉我们错误的确切来源(文件/行)。
-
是的,这是确切的代码。我用抛出的那一行更新了帖子。感谢您的帮助
-
您是否使用自动链接来选择要链接的正确 boost 库?如果您使用 CRT 静态库而 boost 在 DLL 中使用 CRT,则可能会出现此类问题,反之亦然。
-
我没有使用自动链接,我手动指定了我需要链接的所有库。这是我第一次使用 vc++,我以前只在 Linux 上使用 gnu 工具在 C++ 中编程,实际上我不知道 windows CRT 以及如果我静态链接它如何检查它。我会尽快检查出来。
标签: c++ boost boost-filesystem