Deleting a file

D

Dave Theese

Hello all,

Back in C, the remove() API was the language standard way to remove a file.
I have not been able to find a similar facility in the streams classes. Can
anyone tell me if such a facility exists?

I'd rather not resort to the old C API or use a non-standard API unless it's
necessary...

Thanks,
Dave
 
G

Greg P.

| Back in C, the remove() API was the language standard way to remove a
file.
| I have not been able to find a similar facility in the streams classes.
Can
| anyone tell me if such a facility exists?
None that I am aware of.

| I'd rather not resort to the old C API or use a non-standard API unless
it's
| necessary...

The "old C API" is wrapped for C++ by including cstdio. Then call
std::remove(). C++ programmers are constantly using the C library for such
things, and that was the intention by keeping it (besides regression and
backwards compatibility).
 
A

Adam Fineman

Dave said:
Hello all,

Back in C, the remove() API was the language standard way to remove a file.

That is also true in C++.

This:
///////////////////
#include <cstdio>
#include <cstdlib>

using namespace std;

int main() {
if (remove("somefile.txt")) {
perror("remove");
exit(1);
}
return 0;
}
//////////////////

Is a valid C++ program.
I have not been able to find a similar facility in the streams classes. Can
anyone tell me if such a facility exists?
Nothing in the streams classes, no.
I'd rather not resort to the old C API or use a non-standard API unless it's
necessary...

Why not? I can understand why you'd prefer using the streams classes
over C I/O, but why for deleting files?

- Adam
 
G

Greg P.

| Why not? I can understand why you'd prefer using the streams classes
| over C I/O...

I can't <g>
 
K

Kevin Goodsell

Dave said:
Hello all,

Back in C, the remove() API was the language standard way to remove a file.
I have not been able to find a similar facility in the streams classes. Can
anyone tell me if such a facility exists?

I'd rather not resort to the old C API or use a non-standard API unless it's
necessary...

remove() is a function, not an API. And it's the only thing that I know
of that exists in C++ that allows anything remotely similar to what you
want to do.

-Kevin
 
G

Greg P.

| For those of you who would say this without the '<g>':
| http://parashift.com/c++-faq-lite/input-output.html

The only reason for me not liking iostreams is the bulkiness of it (at least
the compilers I've used: msvc, borland, intel, digital mars, gcc) compared
to the C equivalents. But this is just my opinion, and I know that with the
added object footprint comes excellent type-safety and all that good stuff.
I guess that I am just too accustomed to using the printf/scanf family. Also
I know that Bjarne states on his website
(http://www.research.att.com/~bs/bs_faq.html#Hello-world) stating that it's
all in the implementation...I just haven't found a good C++ std lib that
does just that.

I've seen wars errupt over such controversial subject and I am not attemping
to start one, just stating my opinion. For beginners iostreams is almost a
must as it does most the the error checking for them. For seasoned
developers and small projects, being *one* with your code prevents any
errors at all omitting the need for the iostreams checking.

Oh, and another thing, the overloaded left and right shift operators bug me
that they are used for something other than bit shifting =)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,142
Messages
2,570,818
Members
47,362
Latest member
eitamoro

Latest Threads

Top