将文件目录打印到数据结构中

Printing file directory into a data structure

本文关键字:数据结构 打印 文件目录      更新时间:2023-10-16

这段代码假设读取和打印目录中的每个文件,确实如此。现在我希望能够将这些文件放在数据结构中。我选择一个列表,输出在到达实际文件之前被切断。我该如何解决这个问题?

"C:/Users/deonh/Downloads/intranets/intranet1\page99.html"-我想要的列表中的内容

C:/Users/deonh/Downloads/intranets/intranet1-我得到什么。

#include <iostream>
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<fstream>
#include<string>
#include <filesystem>
namespace fs = std::filesystem;
using namespace std;
string path = "C:/Users/deonh/Downloads/intranets/intranet1"; //This gets every single file in the directory
string path5 = "C:/Users/deonh/Downloads/intranets/intranet5";
string path7 = "C:/Users/deonh/Downloads/intranets/intranet7";

int main()
{
list<string>pages;
map<string, int> page;

//Here I am printing the files to make sure the above code works.
for (const auto& entry : fs::directory_iterator(path)) {
std::cout << entry.path() << std::endl;
pages.push_back(path);
}
for (list<string> ::iterator it = pages.begin(); it != pages.end(); it++) {
cout << *it << endl;
}

return 0;
}

您只是在列表中添加了错误的值

pages.push_back(path);

应该是

pages.push_back(entry.path().generic_string());