简体   繁体   English

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

[英]Cannot convert Boost path iterators to strings

I'm attempting to get the following code from nmdepend to compile 我试图从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;
}

However it is generating the following compiler error 但是它会生成以下编译器错误

/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

How should this code be modified so that a string is returned yet the manipulation that is being attempted by using an iterator is maintained? 如何修改此代码以便返回一个字符串,但是仍然保持使用迭代器尝试的操作?

path is not implicitly convertible to string. path不可隐式转换为字符串。 This should work though: 这应该工作:

return p->string();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM