微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

C中的文件全局

Perl成语的C语言是什么?
my @files = glob("file*.txt");
foreach my $file (@files) {

   # process $file
}

解决方法

没有标准的C模式来模拟,因为没有标准的C功能来读取目录的内容.你可以做的是使用 Boost.Filesystem
#include <boost/filesystem.hpp> // plus iostream,algorithm,string,iterator
using namespace boost::filesystem; // and std

struct pathname_of {
    string operator()(const directory_entry& p) const {
        return p.path().filename(); // or your creativity here
    }
};

int main(int argc,char* argv[])
{
    transform(directory_iterator("."),directory_iterator(),ostream_iterator<string>(cout,"\n"),pathname_of());
    return 0;
}

原文地址:https://www.jb51.cc/c/113621.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐