Сохранение имен файлов в строку с использованием dirent.h
Поэтому я хочу сохранить имя файла в строку, но я не знаю, как это сделать. Пока это мой код, я хочу сохранить имя файла в переменную y, но вывод, который я получаю, обычно просто бессмысленный.
#include <iostream>
#include <string>
#include <dirent.h>
#include <typeinfo>
using namespace std;
int main()
{
DIR *dir;
string str,test;
struct dirent *ent;
if ((dir = opendir("F:\\Test\\")) != NULL) {
/* print all the files and directories within directory */
while ((ent = readdir(dir)) != NULL) {
printf("%s\n", ent->d_name);
//test = ent_ > d_name;
string y = ent->d_name;
printf("%s\n", y);
}
closedir(dir);
}
else {
/* could not open directory */
getline(cin, str);
perror("");
}
getline(cin, str);
return 0;
}