I just started looking into C++ and have been reading a book and am only a couple of chapters in.
I thought a good exercise would be to print out a directory. When I look it up, I see this nice for
loop that is driving the train from.
for (const auto & entry : fs::directory_iterator(path))
std::cout << entry.path() << std::endl;
My next logical step was going to store these values in a vector or an array.
For the past three hours, I have not been able to figure it out. What is entry
? Is it a constant? Is it a string? What's stopping me from placing it in a vector? I can't get this code to run.
I am sorry for the basic question, I just need some conceptual clarification.
This is my code, push_back()
does not take constants and I can't convert the constants to a string. What am I missing?
auto filepath()
{
std::vector <string> lis;
std::string path = "C:/Users/Derek Comeau/3D Objects";
for (const auto& entry : filesystem::directory_iterator(path)) {
const string paths = entry.path();
lis.push_back(paths);
}
}