首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::remove

Defined in header <cstdio>

?

?

int remove( const char* fname );

?

?

指定的字符串所标识的文件。fname...

如果当前进程或其他进程打开了该文件,则此函数的行为是实现定义的%28,特别是POSIX系统取消文件名的链接。尽管文件系统空间不会被回收,即使这是文件的最后一个硬链接,直到最后一个运行的进程关闭该文件,但Windows不允许删除该文件%29。

参数

fname

-

pointer to a null-terminated string containing the path identifying the file to delete

返回值

?0?如果成功或错误值为非零。

注记

POSIX指定关于此函数的行为的许多其他细节。

标准库还定义了一个函数模板。std::remove使用一对迭代器和一个值,这个重载是一个标准的算法...

二次

代码语言:javascript
复制
#include <iostream>
#include <fstream>
#include <cstdio>
int main()
{
    bool ok = static_cast<bool>(std::ofstream("file1.txt").put('a')); // create file
    if(!ok) { std::perror("Error creating file1.txt"); return 1; }
    std::cout << std::ifstream("file1.txt").rdbuf() << '\n'; // print file
 
    std::remove("file1.txt"); // delete file
 
    bool failed = !std::ifstream("file1.txt");
    if(failed) { std::perror("Error opening deleted file"); return 1; }
}

二次

可能的产出:

二次

代码语言:javascript
复制
a
Error opening deleted file: No such file or directory

二次

另见

removeremove_all (C++17)(C++17)

removes a file or empty directoryremoves a file or directory and all its contents, recursively (function)

rename

renames a file (function)

C删除文档

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com