我想std::filesystem在我的项目中使用,这将允许我显示.txt当前目录中的文件(我使用 Ubuntu,我不需要 Windows 函数,因为我已经在 StackOverflow 上看到了一个)。
这是我的 GitHub 存储库:
https://github.com/jaroslawroszyk/-how-many-pages-per-day
我有一个解决这个问题的方法,如下所示:
void showFilesTxt()
{
DIR *d;
char *p1, *p2;
int ret;
struct dirent *dir;
d = opendir(".");
if (d)
{
while ((dir = readdir(d)) != NULL)
{
p1 = strtok(dir->d_name, ".");
p2 = strtok(NULL, ".");
if (p2 != NULL)
{
ret = strcmp(p2, "txt");
if (ret == 0)
{
std::cout << p1 << "\n";
}
}
}
closedir(d);
}
}
Run Code Online (Sandbox Code Playgroud)
但是我在这里输入的代码想使用C++17,但我不知道如何找到文件.txt,现在我写道:
for (auto &fn …Run Code Online (Sandbox Code Playgroud)