>>36
boostで書いてみた.
#include <iostream>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/fstream.hpp>
using namespace std;
void show (const boost::filesystem::path &p) {
boost::filesystem::directory_iterator end;
for (boost::filesystem::directory_iterator itr (p); itr != end; ++ itr) {
if (boost::filesystem::is_directory (*itr))
show (*itr);
else {
string filepath (boost::filesystem::complete (*itr).string ());
cout << "#############" << filepath << "#############" << endl;
ifstream ifs (filepath.c_str ()); if (!ifs) exit (1);
string buf;
while (getline (ifs, buf))
cout << buf << endl;
}
}
}
int main () {
show (boost::filesystem::path ("hoge"));
return 0;
}
初めて使ったので慣れてる人からみたら変なとこがあるかもしれないけど,こんな感じで書けますよ.