简体   繁体   中英

Cannot convert Boost path iterators to strings

I'm attempting to get the following code from nmdepend to compile

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. This should work though:

return p->string();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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