Computing.Net > Forums > Programming > deleting a file (C++)

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

deleting a file (C++)

Reply to Message Icon

Name: guy0089
Date: January 24, 2005 at 18:26:35 Pacific
OS: windows 2000
CPU/Ram: NA
Comment:

I'm a C++ student at my high school. I was wondering how to delete a file. Please don't show me only the command, but the context in which it is used as well. Include any neccesary libraries. In addition, I was wondering if it is possible to delete an entire folder and all its content. If so, show me the command in context with any neccasry libraries.



Sponsored Link
Ads by Google

Response Number 1
Name: sen (by santanusen_82)
Date: January 24, 2005 at 21:04:53 Pacific
Reply:

Hi,

To delete a file using C++ you need to use the remove funtion. The function is declared in stdio.h . It looks like

#include <stdio.h>

int remove(const char *pathname);

For example, if you want to delete a file named myfile.txt the code will be

#include<stdio.h>

int main()
{
if(remove("myfile.txt") == -1)
{
fprintf(stderr,"Remove failed");
exit(EXIT_FAILURE);
}

exit(EXIT_SUCCESS);
}


Good day.

Santanu Sen
National Institute of Technology
Durgapur
India


0

Response Number 2
Name: tImmaY
Date: January 26, 2005 at 14:13:52 Pacific
Reply:

and why exactly do you want to delete files and folders..? lol :-\


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: deleting a file (C++)

deleting a file with CBuilderX www.computing.net/answers/programming/deleting-a-file-with-cbuilderx/12046.html

c++ deleting a file www.computing.net/answers/programming/c-deleting-a-file/11727.html

Deleting a file in VB www.computing.net/answers/programming/deleting-a-file-in-vb/18199.html