我无法弄清楚如何在FL/filename.h
模块中使用fl_filename_list函数。我也在互联网上找不到任何好的例子或教程。任何人都可以提供一个很好的例子吗?
答案 0 :(得分:2)
fl_filename_list()只是围绕scandir()函数的跨平台包装器。如果您熟悉那个,那么您也应该轻松使用fl_filename_list()。
// FILE: fl_filename_list.cpp
// RUN: fltk-config --compile fl_filename_list.cpp && ./fl_filename_list
#include <FL/filename.H>
#include <iostream>
int main() {
dirent** list;
// by default we will use the fl_numericsort() function declared in
// the filename.H . Here are others, and you can certainly
// use the source to find out how to write your own ;)
/* code snippet: filename.H
00107 FL_EXPORT int fl_alphasort(struct dirent **, struct dirent **);
00108 FL_EXPORT int fl_casealphasort(struct dirent **, struct dirent **);
00109 FL_EXPORT int fl_casenumericsort(struct dirent **, struct dirent **);
00110 FL_EXPORT int fl_numericsort(struct dirent **, struct dirent **);
*/
int numOfFiles = fl_filename_list("/tmp", &list);
// or, int numOfFiles = fl_filename_list("/tmp", &list, fl_alphasort);
std::cout << "Number of files: " << numOfFiles << std::endl;
for (int i = 0; i < numOfFiles; i++)
std::cout << list[i]->d_name << std::endl;
}
return 0;
}