读取文件夹下的所有文件名,并将文件名存放到容器中。
//获取文件夹下的所有文件的文件名,并存放到vector中
std::vector<std::string> getfile(const std::string &path) {
std::vector<std::string> vPath;
intptr_t handle;
struct _finddata_t fileinfo;
handle = _findfirst(path.c_str(), &fileinfo);
if (handle == -1) {
return vPath;
}
do {
vPath.push_back(fileinfo.name);
} while (!_findnext(handle, &fileinfo));
_findclose(handle);
return vPath;
}
得到的容器如果为空,则说明没有读取到文件。
本文介绍了一种使用C++编程语言读取指定文件夹下所有文件名称并将其存储到vector容器中的方法。通过调用_findfirst和_findnext函数遍历文件夹,最终返回包含所有文件名的容器。

4517

被折叠的 条评论
为什么被折叠?



