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: 
Finally I completed the short project.To get the list of files and sub directories, I made use of `.NET Framework namespace "System"`.It has got classes like "`FileInfo`" and "`DirectoryInfo`"(both belong to `System::IO`) which do the above required task.But here,all the string related stuff is of `System::String` , not of `std::string`.To convert `System::String` to `std::string`, I used the following code(I got this conversion's code from a forum and it worked fine without any error):

```
string Str2str(String ^a)
{
array<Byte> ^chars = System::Text::Encoding::ASCII->GetBytes(a);
pin_ptr<Byte> charsPointer = &(chars[0]);
char *nativeCharsPointer = reinterpret_cast<char *>(static_cast<unsigned char *>(charsPointer));
string native(nativeCharsPointer, chars->Length);
return native;
}

```

Here is a short code for getting list of sub directories from a drive(D: drive is going to be searched):

```
 #include<iostream>
        #using<mscorlib.dll>
        using namespace strd;        
        using namespace System;
        using namespace System::IO;

int main()
    {int count=50;
string name[count];//to hold directories names
string b;
int s=0;
DirectoryInfo^ di = gcnew DirectoryInfo("d:\\");
if(di->Exists)
{array<DirectoryInfo^>^diArr = di->GetDirectories();
Collections::IEnumerator^ myEnum = diArr->GetEnumerator();
while ( myEnum->MoveNext() )
{DirectoryInfo^ dri = safe_cast<DirectoryInfo^>(myEnum->Current);

      String ^a=(dri->Name->ToString());
      int n=b.size();
      b=Str2str(a); `// code given in the starting`
      if (s<count)
      {name[s]=b;
      s++;}

}

```

This involves Managed C++ knowledge. Visit these:

[.NET Programming Guide](http://msdn.microsoft.com/en-us/library/68td296t.aspx)

[C++: The Most Powerful Language for .NET Framework Programming](http://msdn.microsoft.com/en-us/library/ms379617%28VS.80%29.aspx)

I compiled this on Visual Studio 2008. I will be very grateful if you appriciate my effort.Further suggestions are most welcomed.
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