Question: I am using the directory class to get this information but unable to assign this data to a data member of my own class. i am doing an oop project. Furthermore,I want to use the concept of Dynamism(containment).I have created two class, mydirectory and myfiles as under:

```
class files
{
    string fname[25];
public:
    files()
    {
      fname=NULL;
    }

};

class directory
{ private:
    directory *d;
    string *dname[25];   //* to show there may be a subdirectory,there may be not.
    files *ff[25];       // data member string *fname[25];
int numd,numf;
public:
    directory()
    {
    numd=0;numf=0;
    }

```

Now when if I want to use the statment:

```
 Directory::GetDirectories("D:\\"); 

```

how can I assign the directory names to "dname" of directory class.

I dont want to include a third party software.

also i need help on the topic: how can a file (doc file/pdf/txt/pwt etc) can be opened from c++ code outside the console? I am very worried. please help me. thanks in advance.

I am new to c++ so please forgive if there are any errors in pointer handling, as I am doing this containment for the first time. I also need some reading stuff.

Answer: 
The simplest way to do it in C++ is using boost::filesystem.

As long as the path is a directory you can iterate over it using either a directory\_iterator or a recursive\_directory\_iterator.

eg:

```
boost::filesystem::path dirname( "D:\\" );

std::vector<boost::filesystem::path> topLevel( directory_iterator(dirName), 
      directory_iterator() );

std::vector<boost::filesystem::path> wholeDrive( 
       recursive_directory_iterator(dirName), recursive_directory_iterator() );

```
As said CashCow, boost::filesystem

As a general rule, in C++ for such examples, you don't need any pointer. Here a some mistakes you should correct:

```
string fname[25];

```

This declares an array of 25 strings. You probably wanted a string of 25 chars ? Well, in std::string, you don't need to care about the length. std::string fname; is enough

```
std::string file_name;
file_name = "baz.txt";

fname=NULL;

```

If fname is a string, then it's not a pointer. So you can't assign NULL to it. A std::string is by default initialized as an empty string. You can leave the whole constructor out.

```
string *dname[25]

```

I suppose you wanted to have an array of string. Just use :

```
std::vector<std::string> dnames;
dnames.push_back("foo");
dnames.push_back("bar"); // dnames now contains {"foo","bar"}

```

And you'll have a dynamically resizable vector of strings.

See : no need of any pointer. No need for any new