我在 C++ 中使用 dirent.h 以获取我的目录中的可用目录和文件,除了可用目录和文件之外,它还列出了一个“。” 和“..”为了删除它们,我在打印之前添加了一个 if 语句。代码如下:
if ((dir = opendir (".")) != NULL) {
while ((ent = readdir (dir)) != NULL)
{
if( !strcmp( ent->d_name, "." )){
printf ("%s\n", ent->d_name);
}
closedir (dir);
}
}
else {
//could not open directory
printf("Error opening directory");
}
它没有给我编译错误,但在执行时给我“双重免费或损坏(顶部):0x00000000016d3010 *** 中止(核心转储)”我该如何解决?