shared pointer
2024-09-02 15:04:26
#include <string>
#include <fstream>
#include <memory>
#include <cstdio>
class FileDeleter
{
private:
std::string filename;
public:
FileDeleter(const std::string& fn)
:filename(fn){}
void operator()(std::ofstream* fp){
fp->close();
std::remove(filename.c_str());
}
};
int main()
{
std::shared_ptr<std::ofstream> fp(new std::ofstream("tmpfile.txt"),FileDeleter("tmpfile.txt"));
}
最新文章
- POJ 2752 Seek the Name, Seek the Fame [kmp]
- 编译可在Android上运行的qemu user mode
- (转)Silverlight控件关系理解
- Fiddler进行模拟Post提交json数据,总为null解决方式
- SPOJ371 Boxes(最小费用最大流)
- 人活着系列之平方数 分类: sdutOJ 2015-06-22 17:10 7人阅读 评论(0) 收藏
- 记一次web项目总结
- Windows下bmp文件格式
- 嵌入式开发软件环境:uboot、kernel、rootfs、data布局分析
- 触摸事件 Touch MotionEvent ACTION
- IOS通过PushSharp开源框架发送推送
- 生产环境中CentOS7部署NET Core应用程序
- 左倾堆(C#)
- 队列工厂之RedisMQ
- SQLServer之分离数据库
- [Swift]LeetCode326. 3的幂 | Power of Three
- Centos 7 搭建FTP详细配置步骤方法
- [SQL Server]无法创建 SSIS 运行时对象,请验证 DTS.dll 是否可用及是否已注册
- 【python】python性能分析--待完善
- HDU 1171 (01背包问题)
热门文章
- Computer Vision_33_SIFT:Evaluation of Interest Point Detectors——2000
- 一个基于TCP/IP的小项目,实现广播消息的功能。(超详细版)
- keil结合st-link使用SWO的两种调试方法笔记
- 洛谷P2114 起床困难综合症【位运算】【贪心】
- 6、Spring Boot 2.x 集成 MyBatis
- 组件化网页开发 / 步骤二 &#183; 2-11 jquery的ajax方法 以及下一章跨域没懂
- xShell终端中文乱码-解决方法
- git error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version
- 031_检测 MySQL 服务是否存活
- 2018 Nowcoder Multi-University Training Contest 2