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: 
As this is marked homework, we're not going to be helping you much by giving you the correct answer. But I will point you in the right direction.

You've indicated you're doing this under Visual C++. Well without using any third party libraries but just what's built in, you'll need to access the Win32 API.

FindFirstFile() & FindNextFile() are what you need.

You'll call FindFirstFile first off to obtain the directory handle.
The parameter is the D:\ that you're passing into your class.

Then call FindNextFile in a while loop.

e.g. The basic principle of using those API's is

```
HANDLE h = FindFirstFile("D:\\");
WIN32_FIND_DATA data;
while (FindNextFile(h, &data))
{
   // Check if it's a directory or not
   if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
     // Add to dname
   }
}

```

Consider using std::vector for your dname instead of string\*
because you're stuck with 25 entries. Using vector it'll grow for you.
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