c++读取文件夹中所有图片名字

#include 
#include
using namespace std;
int main() {
	//cv::Mat image0 = cv::imread(path0, 1);
	//cv::Mat image1 = cv::imread(path1, 1);
    //开始遍历文件夹中所有图片
    intptr_t handle;//用于查找句柄
    struct _finddata_t fileinfo;//文件信息的结构体
    handle = _findfirst("G:/MMS_Picture/*.jpg", &fileinfo);//第一次查找
    if (handle == -1)
        return -1;
    printf("%s\n", fileinfo.name);//打印出第一个文件名
    string last_img=fileinfo.name;
    string current_img;
    while (!_findnext(handle, &fileinfo))
    {
        current_img = fileinfo.name;
        printf("%s\n", fileinfo.name);
        last_img = fileinfo.name;
    }
    _findclose(handle);//别忘了关闭句柄
    //Mat img_object = imread(path0, 1);
    //Mat img_scene = imread(path1, 1);
	//cv::waitKey(0);
	return 0;
}

读取为vector

你可能感兴趣的:(c)