Remove file in C++ under UNIX

前端 未结 5 943
悲&欢浪女
悲&欢浪女 2021-02-07 00:46

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

5条回答
  •  名媛妹妹
    2021-02-07 01:24

    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.

提交回复
热议问题