无法将Boost路径迭代器转换为字符串

时间:2012-02-29 00:16:47

标签: c++ boost stl compiler-errors boost-filesystem

我正在尝试从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;
}

但是它正在生成以下编译器错误

/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

如何修改此代码以便返回一个字符串,但仍保留使用迭代器尝试的操作?

1 个答案:

答案 0 :(得分:2)

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

return p->string();