在UNIX下使用C ++删除文件 [英] Remove file in C++ under UNIX

查看:89
本文介绍了在UNIX下使用C ++删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你们通常如何在Linux OS上删除文件?我正在考虑使用unlink函数调用,但是我想知道您是否有更好的主意,因为C ++标准没有提及文件删除操作,并且它取决于系统.

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.

推荐答案

是的-C ++标准将这些内容留给操作系统使用,因此,如果您使用的是Linux(或任何POSIX系统),则

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.

C标准提供了 remove() ,您可以尝试,但请记住,其,因此它并不能真正阻止您进入特定于平台的文件系统详细信息(链接等).

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.

这篇关于在UNIX下使用C ++删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆