2012-02-29 32 views
0

我试图但是它生成以下编译器错误无法转换加速路径迭代器为字符串

/Users/nick/Software/nmdepend/src/Bfd.cpp: In static member function ‘static const std::string Bfd::packageName(const boost::filesystem3::path&, int)’: 
/Users/nick/Software/nmdepend/src/Bfd.cpp:27: error: conversion from ‘const boost::filesystem3::path’ to non-scalar type ‘const std::string’ requested 

此代码应如何摆脱nmdepend下面的代码编译

const std::string Bfd::packageName(const fs::path& path, int packageLevel) 
{ 
    fs::path::iterator p = path.end(); 
    --p; 

    for(int i = 0; i < packageLevel; ++i) 
     --p; 

    return *p; 
} 

修改,以便字符串返回但正在尝试通过使用迭代器的操作被维护?

+0

不应该是“返回(* p).string();” ? – 2012-02-29 00:40:42

回答

2

path不能隐式转换为字符串。这应该虽然工作:

return p->string(); 
+0

或者也许p-> native()。看起来他们已经改变了很多。 OP,请阅读http://www.boost.org/doc/libs/1_49_0/libs/filesystem/v3/doc/reference.html – Duck 2012-02-29 00:49:30

+0

@Duck:由此返回的类型将随环境而变化。它会在Windows上返回'std :: basic_string ',在POSIX系统上返回'std :: basic_string '。 'string'函数进行必要的转换以将其转换为'std :: string'。 – 2012-02-29 01:13:24

+0

啊,谢谢。还有一个重新审视的API。 – Duck 2012-02-29 01:30:22