将文件目录打印到数据结构中
Printing file directory into a data structure
这段代码假设读取和打印目录中的每个文件,确实如此。现在我希望能够将这些文件放在数据结构中。我选择一个列表,输出在到达实际文件之前被切断。我该如何解决这个问题?
"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());
相关文章:
- 链表,反向函数,数据结构
- 如何使用set实现无序数据结构?
- 我们可以将数据永久保存为数据结构吗?
- C++中的可变长度数组/数据结构
- 用于存储由空格分隔的字符串的 C++/C 数据结构
- 通过 NIF 从C++返回自定义数据结构
- 编译器上的策略数据结构不起作用
- 尝试构建"lock-free"数据结构C++
- 设计将引用元素移动到开头的数据结构.C++
- 在学习数据结构之前对STL有一个了解是好的吗?
- 如何解析表示树状数据结构的字符串
- 我对数据结构、双向链表有一些问题
- googletest:测试太大的数据结构
- C++ 打印包含数据结构的数组
- 使用链表数据结构打印多项式
- 将文件目录打印到数据结构中
- 从右到左计算当前索引中的数据结构中的元素数,并打印每个元素的计数
- 以十六进制打印数据结构值
- C++数据结构(标准库)转储(如 Python 打印函数)
- trie数据结构并打印所有子字符串