ls命令的简单实现

#include <iostream>
#include <dirent.h>

using namespace std;

int main(int argc, char *argv[]) {
    DIR *dp;
    struct dirent *drp;
    if (argc != 2)
        cout << "缺少参数" << endl;
    if ((dp = opendir(argv[1])) == NULL) {
        cout << "无法打开 " << argv[1] << endl;
        return 1;
    }
    while ((drp = readdir(dp)) != NULL)
        cout << drp->d_name << endl;
    return 0;
}
上一篇:R&C总结


下一篇:int  main( int  argc, char**  argv )