はじめまして
ディレクトリの中にあるすべての画像ファイルを読むということなら
まずはディレクトリの中の画像ファイル名を拾うことから始めましょう
以下はC言語で取得する方法ですが、C++17が使える環境なら
もう少し簡単な方法があります
c++
1#include <iostream>
2#include <string>
3#include <string.h>
4#include <cstdlib>
5#include <dirent.h>
6
7
8using std::cout;
9using std::cerr;
10using std::endl;
11using std::string;
12
13
14int main(int argc, char** argv)
15{
16 // 検索するフォルダを指定する
17 string path = "./data/";
18 DIR *dp;
19
20 // ディレクトリのポインタを取得
21 dp = opendir(path.c_str());
22
23 if(dp==NULL)
24 cerr << "not found directory" << endl;
25
26 // ディレクトリ内を読み込む
27 dirent *entry = readdir(dp);
28
29 // ディレクトリ内のすべての情報を一個毎に読む
30 while(entry != NULL){
31 if(entry != NULL){
32
33 const char *ext = strrchr(entry->d_name, '.');
34
35 // 拡張子が正しいか比較する
36 if(strcmp(".png", ext) == 0){
37
38 // ファイル名を取得する
39 cout << path << entry->d_name << endl;
40
41 /**
42 ここに画像を読み込む処理を追加する
43 **/
44 }
45 }
46 entry = readdir(dp);
47 }
48}