I'm having some trouble with directories & c++. I'm using Visual Studio 2013 on a Windows setup.
Directory : .../Files which contains some text files (f1.txt , f2.txt , f3.txt)
I need the function to go through all the files in that directory one by one.
A file is open - cout the filename
//Do some stuff
close - then move to next file
I have the code to read a single file. But I have no idea how to go through all of them & display the names.
void goThroughDirectory()
{
while("there are remaining files , do something , then go to next one")
{
cout << "The Name of the File Currently being processed" << endl;
// While inside a file
ifstream FileX("FileName.txt");
int lineNum = 0;
string s;
while (!FileX.eof())
{
getline(FileX, s);
if (s.size() != 0)
{
lineNum++;
cout << s << endl;
}
}
}
}
the expected output should be :
// file name
f1
// contents
a
b
c
// file name
f2
// contents
a
b
c
.......