1、问题描述,在批量读取文件的的时候需要用到DIR及其他的一些函数。而DIR需要头文件#include <dirent.h>。然而加头文件的时候出现了如图1的状况。
图1:nodirent.h文件图片
2.所以在网上找到了一个dirent.h文件,地址如下所示http://www.softagalleria.net/download/dirent/?C=M;O=D,在里面找一个最新的dirent版本下载。下载图片如图2所示
图2 dirent.h下载图
3、然后将dirent文件解压缩,将其中的dirent.h放到这个文件夹下E:\program\vs2010\VC\include,实际情况根据你自己的看修改这个目录。然后就好了。
4、批量读取文件的程序c++实现源码
#include "stdafx.h"
#include <stdio.h>
#include <dirent.h>
#include <fstream>
#include <sys/types.h>
#include <vector>
#include<iostream>
#include <string>
#include <stdlib.h>
using namespace std;
void main ()
{
DIR *dp;
struct dirent *dirp;
vector <std::string> filename;
if((dp=(opendir("fire")))==NULL)
perror("open dir error");
while((dirp=readdir(dp))!=NULL){
filename.push_back(dirp->d_name);
}
for(int i=0 ; i<filename.size() ; i++){
cout<<filename[i]<<endl;
}
closedir(dp);
int temp;
cin>>temp;
}
程序执行结果如下图3所示
图3:程序执行效果图
5、祝愿所有的孩子:能够找出BUG,修正错误。
6、参考文献
http://blog.csdn.net/tracyliang223/article/details/17399939
http://blog.sina.com.cn/s/blog_9ce5a1b501015k17.html
http://www.softagalleria.net/download/dirent/?C=M;O=D