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 に答える