c++ 中的取消链接与删除

发布于 2024-08-20 02:54:23 字数 28 浏览 5 评论 0 原文

C++ 中的删除和取消链接函数有什么区别?

What is the difference between remove and unlink functions in C++?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

童话 2024-08-27 02:54:23

除了 unlink 是特定于 UNIX 的事实(正如 Chris 所指出的)之外,我们在 POSIX 手册中读到:

如果path没有命名目录,remove(path)相当于unlink(path)。
如果 path 指定一个目录,remove(path) 等价于 rmdir(path)。

至于目录传递的unlink,我们读到:

路径参数不得命名目录,除非进程具有适当的权限并且实现支持在目录上使用 unlink()。 (...)应用程序应该使用 rmdir() 来删除目录。

Apart from the fact that unlink is unix-specific (as pointed out by Chris), we read in the POSIX manual:

If path does not name a directory, remove(path) is equivalent to unlink(path).
If path names a directory, remove(path) is equivalent to rmdir(path).

As for the directory-passed unlink, we read:

The path argument must not name a directory unless the process has appropriate privileges and the implementation supports using unlink() on directories. (...) Applications should use rmdir() to remove a directory.

给我一枪 2024-08-27 02:54:23

remove 是可移植的,而 unlink 是 Unix 特定的。 :-P

remove is portable, and unlink is Unix-specific. :-P

后知后觉 2024-08-27 02:54:23

remove() 函数删除路径指定的文件或目录。

如果path指定一个目录,remove(path)相当于
rmdir(路径)。否则,它相当于unlink(path)

来自:手动删除

祝你好运 ;)

The remove() function removes the file or directory specified by path.

If path specifies a directory, remove(path) is the equivalent of
rmdir(path). Otherwise, it is the equivalent of unlink(path).

From: man remove.

Good Luck ;)

青衫负雪 2024-08-27 02:54:23

unlink 不是特定于 UNIX 的,我不知道为什么人们这么说。参见 io.h。尽管您可能需要执行类似

#define unlink _unlink

http 的 操作://msdn.microsoft.com/en-us/library/1c3tczd6%28v=VS.100%29.aspx

http://msdn.microsoft.com/en-us/library/2da4hk1d%28v=VS.100%29.aspx

unlink is not unix-specific, i don't know why people're saying that. see io.h. although you'll probably have to do something like

#define unlink _unlink

http://msdn.microsoft.com/en-us/library/1c3tczd6%28v=VS.100%29.aspx

http://msdn.microsoft.com/en-us/library/2da4hk1d%28v=VS.100%29.aspx

情绪 2024-08-27 02:54:23

remove() 是 C++ 标准 (N4860 29.11.14.30) 的一部分。 unlink() 不是。

remove() is part of the C++ standard (N4860 29.11.14.30). unlink() is not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文