Hi. Here is a simple beginners program. It uses "if_else" and returns no information. After execution, it deletes files within the same directory as the exe. Enjoy.

Edited 4 Years Ago by deceptikon: Converted to a code snippet

/* By lil_bit 2012: Free Open Source Code for all*/
/* remove example: This deletes file(s) from location the .exe is located.*/
/* Also notice only two headers with only one antiquated.*/
/* Please use care when using code*/
/* Namesta*/

#include <iostream>
#include <stdio.h>

int main ()
{
    if( remove( "testd1.txt" ) != 0 )
        perror( "Error deleting file" );
    else
        puts( "File successfully deleted" );

    if( remove( "testd2.txt" ) != 0 )
        perror( "Error deleting file" );
    else
        puts( "File successfully deleted" );

    if( remove( "testd3.txt" ) != 0 )
        perror( "Error deleting file" );
    else
        puts( "File successfully deleted" );

    return 0;
}

Hello pyTony. ? Are you saying next progressional step; Better way to simplify code; Suggestion towards next article ? Please clarify. Thank you.

Hello Ravenous! Your posts are very good. Yes it does. Thank you for bringing this to my attention. C++ is very modular so redundancy of similiar code on the net is not uncommon and thank you for the link and would you please grade or elaborate on this code? Thank you.

I'd also study about useful output messages:
Error deleting file -- which file?
File successfully deleted -- which file?

Ravenous, you were right. Looking back through my study folder, I found my notes that cited the link. All I did was repeat the code. Credit to the original owner. Thanks to all for the feedback.

Taking the advice of my peers. Here is a further edit of the code with proper citation. This code pauses to state files are either successfully deleted or displays error message.

/* remove example: This deletes file from location the .exe is located. */
/*Based upon original code found at http://www.cplusplus.com/reference/clibrary/cstdio/remove/ */
/*Code Modify By: lil_bit 2012 */

#include <iostream>
#include <stdio.h>

int main ()
{
  if( remove( "testd1.txt" ) != 0 )
    perror( "Error deleting file testd1.txt" );
  else
    puts( "testd1.txt successfully deleted" );

if( remove( "testd2.txt" ) != 0 )
    perror( "Error deleting file testd2.txt" );
  else
    puts( "testd2.txt successfully deleted" );

if( remove( "testd3.txt" ) != 0 )
    perror( "Error deleting file testd3.txt" );
  else
    puts( "testd3.txt successfully deleted" );

system( "PAUSE" );
return 0;

}

Edited 4 Years Ago by lil_bit: Improving

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;

}

Edited 4 Years Ago by pyTony

Thanks pyTony. Looks alright to me. I'm new to all of this, but, I make the best attempt. Wow, poweroutage and weird hack on me all at the same time. Considering your posts, you know what you are doing. Thank you pyTony. If anything, I am ready to learn.

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.