boost::filesystemでディレクトリ内のファイル一覧を出す

参考


main.cpp

#include <iostream>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/fstream.hpp>

using namespace std;
using namespace boost;
namespace fs = boost::filesystem;

int main(void)
{
  string pt = "/Users/sho/";
  fs::path path = complete(fs::path(pt, fs::native));
  fs::directory_iterator end;
  for (fs::directory_iterator i(path); i!=end; i++){
    string name = pt + i->leaf();
    cout << name << endl;
  }
  return 0;
}


Makefile

SRC = main.cpp
DST = main

prefix=/opt/local
INCPATH=/opt/local/include
LIBPATH=/opt/local/lib

LIBS=$(LIBPATH)/libboost_filesystem-mt.dylib $(LIBPATH)/libboost_system-mt.dylib

all:
	g++ -O $(SRC)  -o $(DST) -I$(INCPATH)/boost $(LIBS)

libboost_filesystem-mt.dylibとlibboost_system-mt.dylibをリンクする必要があった