Кто-нибудь может продемонстрировать fl_filename_list? - PullRequest
1 голос
/ 10 января 2012

Я не могу понять, как использовать функцию fl_filename_list в модуле FL/filename.h.Я также не могу найти хороших примеров или учебников в Интернете.Кто-нибудь может привести хороший пример?

1 Ответ

2 голосов
/ 10 января 2012

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;
}
...