读取某文件下所有的.bmp文件,存到双向链表中并在正点原子显示屏上循环显示
时间: 2024-04-07 09:33:16 浏览: 9
你可以使用以下代码来读取某个文件夹下的所有.bmp文件,并将其存储到双向链表中:
```c++
#include <iostream>
#include <string>
#include <filesystem>
struct Node {
std::string filename;
Node* prev;
Node* next;
};
Node* createNode(std::string filename) {
Node* newNode = new Node;
newNode->filename = filename;
newNode->prev = nullptr;
newNode->next = nullptr;
return newNode;
}
void insertNode(Node** head, std::string filename) {
Node* newNode = createNode(filename);
if (*head == nullptr) {
*head = newNode;
return;
}
Node* current = *head;
while (current->next != nullptr) {
current = current->next;
}
current->next = newNode;
newNode->prev = current;
}
void displayImages(Node* head) {
// 在正点原子显示屏上循环显示
while (true) {
Node* current = head;
while (current != nullptr) {
std::string filename = current->filename;
// 在正点原子显示屏上显示图片
std::cout << "Displaying image: " << filename << std::endl;
current = current->next;
}
}
}
int main() {
std::string folderPath = "path/to/folder"; // 替换为实际的文件夹路径
Node* head = nullptr;
for (const auto& entry : std::filesystem::directory_iterator(folderPath)) {
std::string filePath = entry.path().string();
if (filePath.substr(filePath.find_last_of(".") + 1) == "bmp") {
insertNode(&head, filePath);
}
}
displayImages(head);
return 0;
}
```
请将代码中的`"path/to/folder"`替换为实际的文件夹路径,然后在正点原子显示屏相应的位置显示图片即可。注意,该代码使用了C++17的`std::filesystem`库,所以确保你的编译器支持该库。
希望这能帮到你!如果还有其他问题,请随时提问。