0

I'm sorry if my terminology might be wrong but I have an example code here using the "filesystem" library where it displays all the directory contents and its sub-contents using a for loop and it uses an auto type variable 'p'. I want to convert that into a string to store in a string variable. Is there any way to do this?

#include <filesystem>
namespace fs = std::experimental::filesystem;
int main()
{
    std::string path = "c:\\home\\...some directory";
    for (auto & p : fs::recursive_directory_iterator(path))
    {
        std::cout << p << std::endl;  
    }

    system("pause");
}
slowjoe44
  • 7
  • 3
  • `p` is a reference to `std::directory_entry` see here for methods: http://en.cppreference.com/w/cpp/filesystem/directory_entry – Richard Critten Oct 31 '17 at 14:37
  • Replace auto with the real type - then you are sure you have looked up what you are doing. –  Oct 31 '17 at 15:26

0 Answers0