gpt4 book ai didi

c++ - 从目录 C++ 打开多个文件

转载 作者:行者123 更新时间:2023-11-30 02:35:36 26 4
gpt4 key购买 nike

我试图从一个目录中打开文件,但每次我显示我的文件时,我都会在顶部看到这 3 个点。因此,例如,我打开的目录称为“我的文档”,输出将是 3 个点,如下所示...姓名.txt乔布斯.txt

Names.txt 和 Jobs.txt 是我想要实现的唯一输出,任何人都可以帮忙。

我的代码

int getDoc(string doc, vector<string> &documents){

DIR *dp;
struct dirent *dirp;
if ((dp = opendir(doc.c_str())) == NULL){
cout << "Error(" << errno << ") opening" << doc << endl;
return errno;
}
while ((dirp = readdir(dp)) != NULL){
documents.push_back(string(dirp->d_name));
}
closedir(dp);
return 0;
}

顺便说一句,我使用 dirent.h

最佳答案

.为当前目录,..为上层目录。如果您不想要它们,只需过滤掉它们即可。

关于c++ - 从目录 C++ 打开多个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33464660/

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