C中的文件全局

前端之家收集整理的这篇文章主要介绍了C中的文件全局前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Perl成语的C语言是什么?
  1. my @files = glob("file*.txt");
  2. foreach my $file (@files) {
  3.  
  4. # process $file
  5. }

解决方法

没有标准的C模式来模拟,因为没有标准的C功能来读取目录的内容.你可以做的是使用 Boost.Filesystem
  1. #include <boost/filesystem.hpp> // plus iostream,algorithm,string,iterator
  2. using namespace boost::filesystem; // and std
  3.  
  4. struct pathname_of {
  5. string operator()(const directory_entry& p) const {
  6. return p.path().filename(); // or your creativity here
  7. }
  8. };
  9.  
  10. int main(int argc,char* argv[])
  11. {
  12. transform(directory_iterator("."),directory_iterator(),ostream_iterator<string>(cout,"\n"),pathname_of());
  13. return 0;
  14. }

猜你在找的C&C++相关文章