Hi,

How can i delete the file in the middle of the program in C++

Thanks

Recommended Answers

All 13 Replies

Hi,
How can i delete the file in the middle of the program in C++

Probably in the same manner as in the program head or in the program tail: close all streams associated with the file then use remove(filepath) library function declared in <cstdio>.

boost is unnecessary - anytime anyone suggest a usage.

boost is unnecessary - anytime anyone suggest a usage.

Are you serious? Far from true.

Fortunately, the remove from <cstdio> is a standard library function so no need to fire a nuclear missile to kill a fly. It's an absolutely portable function ;)

It's a great library that should be put to use. It may not be necessary in this case but there's nothing wrong with suggesting alternatives.

It would be perfectly reasonable to use in this case if the programmer has already put Boost in their toolkit.

Are you serious? Far from true.

I should clarify here. Yes, Boost is unnecessary but so is cstdio in this context. But then so is the entire language of C++ or any other high-level language, for that matter.

Every library is there to make our life a little easier and so we don't have to re-invent the wheel everyday. Boost is a great example and should be put to use if someone finds it helpful.

commented: Making stupid statements does not help you prove a point. -3

regexes can be worthwhile.

I should clarify here. Yes, Boost is unnecessary but so is cstdio in this context. But then so is the entire language of C++ or any other high-level language, for that matter.

Every library is there to make our life a little easier and so we don't have to re-invent the wheel everyday. Boost is a great example and should be put to use if someone finds it helpful.

Let's come back to the OP. Is it a question like how to delete file with Boost library? Or it was How can i delete the file in the middle of the program in C++? Correct me, please, if I'm wrong and it was Boost-oriented queston.
Otherwise let's discuss all great (and not only great) libraries where remove file functions exist. Let's consider how to use the Great Boost Library instead STL for streams, big num libraries instead of builtin operator +(POD,POD) and so on...
Keep it simpler ;)...

commented: Adding to the stupidity is not necessary. As you say, back to the OP. -3

Let's come back to the OP. Is it a question like how to delete file with Boost library? Or it was How can i delete the file in the middle of the program in C++? Correct me, please, if I'm wrong and it was Boost-oriented queston.
Otherwise let's discuss all great (and not only great) libraries where remove file functions exist. Let's consider how to use the Great Boost Library instead STL for streams, big num libraries instead of builtin operator +(POD,POD) and so on...
Keep it simpler ;)...

You questioned the merits of Boost. I simply disagreed and stated my opinion, just as you did. ;)

But yes, I did get a little off topic in the last comment, but I thought the clarification was due.

I certainly think my comments have been much more on topic than "boost is unnecessary - anytime anyone suggest a usage."

I'm not sure I understand your emphasis of "in C++". It's as if you're questioning Boost as C++. I would suggest it's more C++ than cstdio, a relic from C.

What's not simple about Boost? And why does an answer have to be simple anyway?

You questioned the merits of Boost. I simply disagreed and stated my opinion, just as you did. ;)

But yes, I did get a little off topic in the last comment, but I thought the clarification was due.

I certainly think my comments have been much more on topic than "boost is unnecessary - anytime anyone suggest a usage."

I'm not sure I understand your emphasis of "in C++". It's as if you're questioning Boost as C++. I would suggest it's more C++ than cstdio, a relic from C.

What's not simple about Boost? And why does an answer have to be simple anyway?

It seems the patient's case is hopeless ;)...
Apropos, <cstdio> is not a relict. It's a part of the C++ Standard (the current and the next).

It seems the patient's case is hopeless ;)...

No need for comments like these. ;) I've done nothing but try to help others in my short time here and I've seen many of your comments and assume you try to do the same.

Apropos, <cstdio> is not a relict. It's a part of the C++ Standard (the current and the next).

If I've suggested otherwise, you've misunderstood me. I'm not sure relict is the best term but I wouldn't take the statement back because I think it pretty accurately describes my thought in that context. That's not to say it doesn't have use or that it shouldn't be used.

I wasn't trying to make a big issue out of this. I was simply trying to suggest that boost::filesystem is an option and a very reasonable one at that. Any further comments were an effort to get an explanation from those that think otherwise. This has yet to come.

If there's no interest in discussing the merit of Boost, I'll consider this discussion over.

Back on topic, before this is locked. The OP can also use POSIX unlink(), Win32 DeleteFile(), or even in desperation system(). Obviously remove() takes care of all of that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.