批量读取图片中关于缺失dirent.h的问题

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ACMSunny

赠人玫瑰,手有余香。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值