How to convert a boost::filesystem::directory_iterator to a const char *
When you dereference the iterator it returns a directory_entry
:
const directory_entry& entry = *path_it;
You can use this along with operator<<
and ostream
, as you've discovered:
std::cout << entry << std::endl;
You could create a string using ostringstream
:
std::ostringstream oss;
oss << entry;
std::string path = oss.str();
Alternatively you can access the path as a string
directly from directory_entry
:
std::string path = entry.path().string();