Re: std::remove
* Victor Bazarov:
craigbennett@hotmail.com wrote:
I am trying to use std::remove to delete a file and have been
encountering some problems. My goal is to pass std::remove a
std::string and remove the file of that name, for example.
Std::string a = "C:\\Documents and Settings\\a.txt";
Std::remove(a.c_str());
However the process fails and returns error code 267 The directory
name is invalid (the directory defiantly exists as does the file). I
figure I am doing something wrong which is quite simple but it is
eluding me!
Your question cannot be answered in the terms of standard C++ language,
which makes it off-topic. Please ask about the error 267 in the newsgroup
that deals with your os, 'comp.os.ms-windows.programmer' (or below).
Well, I don't think it's off-topic at all. But let's note for the
record that the C standard, which the C++ standard defers to for this
std::remove (see table 99), doesn't seem to mention that std::remove
should set errno on failure, so possibly the errno value reported by the
OP /could/ be just a spurious value. std::remove indicates success by
returning 0, and failure by returning non-zero (something, I don't
remember from five seconds ago whether it's specified as -1).
Apart from the uppercase 'S' in 'Std' the OP's code is valid, but since
it wouldn't compile as given, we don't know whether the rest is the
actual code -- dear OP, please post /actual/ code the next time.
Also, the OP fails to check the return value of the function call, and
so also the claim about failure is a bit suspect.
If correct, however, it could be that the function fails because the
file to be removed doesn't exist, or can't be removed.
It could also be that the specified directory actually doesn't exist or
is accessible (it exists and is accessible on my computer, and there the
code, with the 'S' corrected, works fine).
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?