gpt4 book ai didi

c++ - 使用 dirent.h 但文件被跳过

转载 作者:太空宇宙 更新时间:2023-11-04 11:39:50 27 4
gpt4 key购买 nike

我在一个文件夹中有数百张图片,名称为:1.jpg3.jpg4.jpg6 .jpg8.jpg10.jpg15。 jpg, .... 100.jpg, 102.jpg, 103.jpg, 113.jpg 等...

我正在使用 dirent.h 遍历文件,但不知何故 dirent.h10.jpg 和下一个文件开始它提供的突然是 100.jpg 然后是 102.jpg,...为什么它会跳过一些图像?

int main (int argc, const char* argv[] )
{

cv::Mat image;

DIR *dir;
struct dirent *ent;
if ((dir = opendir ("C:\\Users\\Faraz\\Desktop\\Project\\detecting_false_positives_stuff\\face_images\\faces\\")) != NULL) {
ent = readdir (dir);
printf ("%s\n", ent->d_name);
ent = readdir (dir);
printf ("%s\n", ent->d_name);
while ((ent = readdir (dir)) != NULL) {
printf ("%s\n", ent->d_name);

std::string fullPath = std::string("C:\\Users\\Faraz\\Desktop\\Project\\detecting_false_positives_stuff\\face_images\\faces\\") + ent->d_name;

cout<<fullPath;

image = cv::imread(fullPath);

...

}
closedir (dir);
}
return 1;

最佳答案

如果您希望文件按顺序排列,您必须自己对文件进行排序,readdir 不会为您做这些。另见:Does readdir() guarantee an order?

关于c++ - 使用 dirent.h 但文件被跳过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21788527/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com