在 C++ 中取消链接与删除
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2192415/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
unlink vs remove in c++
提问by SyBer
What is the difference between remove and unlink functions in C++?
C++ 中的 remove 和 unlink 函数有什么区别?
回答by Kornel Kisielewicz
Apart from the fact that unlink is unix-specific (as pointed out by Chris), we read in the POSIX manual:
除了 unlink 是特定于 unix 的这一事实(正如 Chris 所指出的),我们在 POSIX 手册中读到:
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).
如果 path 未命名目录,则 remove(path) 等效于 unlink(path)。如果路径命名目录,remove(path) 等价于 rmdir(path)。
As for the directory-passed unlink
, we read:
至于 directory-passed unlink
,我们读到:
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.
除非进程具有适当的权限并且实现支持在目录上使用 unlink(),否则路径参数不得命名目录。(...) 应用程序应使用 rmdir() 删除目录。
回答by Chris Jester-Young
remove
is portable, and unlink
is Unix-specific. :-P
remove
是可移植的,并且unlink
是特定于 Unix 的。:-P
回答by Quentin Perez
The remove()
function removes the file or directory specified by path.
该remove()
函数删除路径指定的文件或目录。
If path specifies a directory, remove(path)
is the equivalent of
rmdir(path)
. Otherwise, it is the equivalent of unlink(path)
.
如果 path 指定目录,remove(path)
则相当于
rmdir(path)
. 否则,它相当于unlink(path)
。
From: man remove
.
来自:man remove
。
Good Luck ;)
祝你好运 ;)
回答by bviktor
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
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/1c3tczd6%28v=VS.100%29.aspx
http://msdn.microsoft.com/en-us/library/2da4hk1d%28v=VS.100%29.aspx
http://msdn.microsoft.com/en-us/library/2da4hk1d%28v=VS.100%29.aspx