【发布时间】:2017-02-02 09:34:01
【问题描述】:
我正在尝试使用 Boost 库读取多个文件的内容。 我已经成功列出了一个文件夹中的所有文件,但我一直在尝试阅读它们......
#include <iostream>
#include "boost/filesystem.hpp"
using namespace std;
using namespace boost::filesystem;
int main(int argc, char* argv[])
{
// list all files in current directory.
// You could put any file path in here, e.g. "/home/me/mwah" to list that
// directory
path p("/home/baptiste/Bureau");
directory_iterator end_itr;
// cycle through the directory
for (directory_iterator itr(p); itr != end_itr; ++itr)
{
// If it's not a directory, list it. If you want to list directories too,
// just remove this check.
if (is_regular_file(itr->path()))
{
// assign current file name to current_file and echo it out to the
// console.
string current_file = itr->path().string();
cout << current_file << endl;
}
}
}
【问题讨论】:
-
搜索
fstream及其衍生(文件流)...