Now just to study about for loop.
pyTony
pyMod
6,299 posts since Apr 2010
Reputation Points: 879
Solved Threads: 984
Skill Endorsements: 26
Er, this looks very similar to the this example on cplusplus.com
ravenous
Practically a Master Poster
681 posts since Jul 2005
Reputation Points: 286
Solved Threads: 111
Skill Endorsements: 8
triumphost
Practically a Master Poster
625 posts since Oct 2009
Reputation Points: 59
Solved Threads: 55
Skill Endorsements: 1
I'd also study about useful output messages:
Error deleting file -- which file?
File successfully deleted -- which file?
WaltP
Posting Sage w/ dash of thyme
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 36
With my not so great C, I meant:
#include <stdio.h>
int main ()
{
char * fn[] = {"testd1.txt", "testd2.txt", "testd3.txt"};
int len = sizeof(fn) / sizeof(char*);
for(int ind=0; ind < len; ind++)
{
if(remove(fn[ind]))
{
printf("Error deleting file ");
perror(fn[ind]);
}
else
printf("%s successfully deleted\n", fn[ind]);
}
return 0;
}
pyTony
pyMod
6,299 posts since Apr 2010
Reputation Points: 879
Solved Threads: 984
Skill Endorsements: 26
Since you are using C++ maybe avoid using C stuff.
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
struct RemoveFile{
bool operator(const std::string& fileToRemove)const{
if( std::remove( fileToRemove.c_str() ) ){
std::cout << "removed: " << fileToRemove << endl;
return true;
}else{
std::cout << "failed to remove: " << fileToRemove << endl;
return false;
}
}
};
int main(){
const std::string files[] = {"f1.txt" , "t2.txt" };
std::vector<std::string> filesToRemove(files, files + sizeof(files)/sizeof(files[0]));
std::for_each(filesToRemove.begin(), filesToRemove.end(), RemoveFile());
return 0;
}
not really tested but give you an idea.
firstPerson
Industrious Poster
4,044 posts since Dec 2008
Reputation Points: 851
Solved Threads: 625
Skill Endorsements: 14