1

我不知道如何在模块中使用fl_filename_list函数。FL/filename.h我在互联网上也找不到任何好的例子或教程。谁能提供一个很好的例子?

4

1 回答 1

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;
}
于 2012-01-10T18:57:51.123 回答