How do you guys typically delete files on Linux OS? I am thinking of using the unlink
function call, but I wonder if you have a better idea, as the C++ standard has no mention of file deletion operation and it is system dependent.
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- How to replace file-access references for a module
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
unlink is the correct way to do it.
Note that recent kernels also offer
unlinkat
. This function is faster thanunlink
if you have a file descriptor on the directory itself.Yep -- the C++ standard leaves this stuff up to the OS, so if you're on Linux (or any POSIX system),
unlink()
is what you've got.The C standard provides
remove()
, which you could try, but keep in mind that its behavior is unspecified for anything other than a 'regular file', so it doesn't really shield you from getting into platform-specific filesystem details (links, etc).If you want something higher-level, more robust, and more portable, check out Boost Filesystem.
The Standard includes a function called remove which does that. Though i would prefer
boost.filesystem
for that (if i already use boost anyway).unlink()
is defined by the POSIX standards, and hence will exist on any POSIX compatible system, and on quite a few that aren't POSIX compatible too.