2012-01-10 101 views

回答

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; 
} 
+0

有在回路的误差,它应该是为'(INT I = 0; I Andy 2017-08-17 11:43:22

+0

更新,谢谢。 – DejanLekic 2017-08-17 14:01:15

相关问题