#include <dirent.h>
#include <iostream>
DIR *dp; //创建一个指向root路径下每个文件的指针
struct dirent *dirp;
string root="./path/"
if((dp = opendir(root.c_str()))==NULL)
cout << "can't open"<< root << endl;
while((dirp = readdir(dp)) != NULL){
cout<< dirp->d_name << endl; // 输出名字
}
但是要注意的是,输出的前两个路径名是无效的,"." 和 ".." 。