d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > String Help > C++
Add Reply New Topic New Poll
Member
Posts: 22,502
Joined: Aug 5 2011
Gold: 0.00
Dec 27 2013 10:20pm
Quote
#include <dirent.h>
#include <iostream>
#include <string>
using namespace std;

int main()
{
    DIR *searchPath = nullptr;
    struct dirent *readPath = nullptr;

    string pos;

    while(true)
    {
        getline(cin, pos);
        searchPath = opendir(pos.c_str());
        if(searchPath == nullptr) return 0;

        while (readPath = readdir(searchPath))
        {
            if(readPath == nullptr) return 0;
            cout << readPath->d_name << endl;
        }
    }
}


Want to be able to += the string so it can further search the folders.

This post was edited by sylz1014 on Dec 27 2013 10:35pm
Member
Posts: 22,502
Joined: Aug 5 2011
Gold: 0.00
Dec 27 2013 11:16pm
figured out how to do so, but will definitely need to modify the code to make it foolproof.

I just added a 2nd string "pos2"
and then after the getline I added pos2+= pos;
and then for the opendir line just changed pos to pos2
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll