I want to read all the files of a directory and print the words in it, all I've done is to store the names of the files to a string array but now how would I do that...
my code for storing file names:
struct dirent *contents;
DIR *dir;
dir= opendir((char*)"text files");
DIR *op;
op= opendir((char*)"text files");
if(!dir){
cout<<"The given directory is not found";
}
else {
string *arr;
int count;
int i=0;
while ((readdir(op)) != NULL){
count++;
}//for the size array equivalent to number of txt files in directory
count=count-2;
arr=new string[count];
while ((contents = readdir(dir)) != NULL) {
string name = contents->d_name;
if (name != "."&&name!="..") {
arr[i]=name;
i++;
}
}
cout<<"\t*The list of files are*"<<endl;
for(int j=0;j<count;j++){
cout<<arr[j]<<endl;
}
}}
Any guidance