读取指定类型的文件名放入vector中

在用opencv提取文件名的时候可以用glob将文件名提取到一个vector里面,那么这个功能能不能提取限定后缀的文件名呢?比如我只想提取bmp文件的文件名

可以的,glob(“路径前缀/图片文件夹/*.bmp”);


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#define TYPE_NAME ".bmp"
using namespace std;

int main() {

    string str = "nihaoma.bmp";
    vector<string> result;
    if (!strcmp((str.substr(str.length() - 4, str.length())).c_str(), TYPE_NAME))
    {
        result.push_back(str.substr(0, str.length() - 4));
    }
    cout << result[0];
    return 0;
}

可以自己实现这种功能,逻辑很简单