临时


#include <dirent.h>
#include <stdio.h>
#include<string.h>
#include<iostream>
using namespace std;

int main()
{
    string a = "/root/";
    string b;
    getline(cin,b);
    string c = a + b;
    const char* d = c.c_str();
    DIR *dirp; 
    struct dirent *dp;
    dirp = opendir(d); //打开目录指针
    while ((dp = readdir(dirp)) != NULL) { //通过目录指针读目录
        printf("%s
", dp->d_name );
    }      
    (void) closedir(dirp); //关闭目录
    return 0;
}
原文地址:https://www.cnblogs.com/gardenofhu/p/6894419.html