读取目录中文件名的方法 C++

以下列出读取目录下所有文件的方法,遇到添加。

方法1 cmd dir + 读文件  

在windows命令行中

dir d:\SVN\myWorld\VS2019\QM_improve\4317server /d/w/s/b > filelist.txt

然后读文件:

void get_finename() {
    ifstream in;
    in.open("filelist.txt", ios::in);
    if (!in) {
        cout << "open file fail!";
        exit(1);
    }
    else cout << "open file success!" << endl;
    while (!in.eof())
    {
        string temp;
        getline(in, temp, '\n');//读每行的最后一个会读取到形如\n6B
        cout << temp << endl;
    }
    in.close();
}
View Code

 

posted @ 2021-04-02 12:01  PiaYie  阅读(167)  评论(0编辑  收藏  举报