0

I am a newbie so please don't be harsh on me for asking simple questions. my main question is how can I read from several files located in a directory sequently using a loop in c++ and perform some actions on them? My code is like this:

string corpus = "corpus.txt";

myfile.open(corpus);
if (myfile.is_open())
    while (!myfile.eof()) 
    {
        //Do something

    }//end of while


    MergeFiles(corpus,count);`

How can I do this actions on a set of files instead of just one.

Old Azhdar
  • 21
  • 5

1 Answers1

1

Looks like you could do one of the following:

  • use windows APIs
  • use third party code

It looks like the simplest way is using diren.h. Look for at the sample code here: How can I get the list of files in a directory using C or C++?

you can use the boost libraries, more specific - the filesystem library. This is more powerful but complicated solution, requires you to use iterators and higher programming methods.

using the windows API is not recommended because it requires dipper understanding of windows, and won't result a portable code. If you want to use it, there is an example in MSDN.

Community
  • 1
  • 1
elyashiv
  • 3,623
  • 2
  • 29
  • 52