c++boost-filesystem

Convert boost/filesystem to string


I'm trying to convert boost::filesystem type to string, but it tell me that "string()" is not a member of the boost::filesystem :

void myClass::encryptFile()
{ 
// Récursion sur un chemin donné
for (boost::filesystem::recursive_directory_iterator end, dir(DirPath); dir != end; ++dir) 
{   
    // Vérification du type de l'objet
    if (!boost::filesystem::is_regular_file(*dir))
    {
    
    
        string ptext = *dir.string();
                    
    }
    
}

How to convert *dir to string ?


Solution

  • Get the boost::filesystem::path first.

    void myClass::encryptFile()
    { 
    // Récursion sur un chemin donné
    for (boost::filesystem::recursive_directory_iterator end, dir(DirPath); dir != end; ++dir) 
    {   
        // Vérification du type de l'objet
        if (!boost::filesystem::is_regular_file(*dir))
        {
        
        
            string ptext = dir->path().string();
                        
        }
        
    }