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;
}
を使用して「グロブ」を模倣できますfnmatch
。ただし、ディレクトリを開いて内容を読み取り、fnmatch
.
標準のAFAIKである直接の同等物はありません。
オールドスクールと呼んでください。
f = popen("ls file*.txt", "r");