C++ ofstream学习

转自:https://blog.csdn.net/kingstar158/article/details/6859379

1.介绍

#include <fstream>
ofstream         //文件写操作 内存写入存储设备 
ifstream         //文件读操作,存储设备读区到内存中
fstream          //读写操作,对打开的文件可进行读写操作 

 打开文件的方式在ios类(所以流式I/O的基类)中定义,有如下几种方式:

 例子:

复制代码
#include <iostream>
#include <time.h>
#include <fstream>

using namespace std;

int main()
{
    ofstream outfile;
    string file="./email.txt";
    outfile.open(file,ios::trunc|ios::out);
    outfile<<"bbb\n";
    outfile.close();
    return 0;
}
复制代码

验证结果,确实会删掉原来的文件,然后重新写入。 

 

posted @   lypbendlf  阅读(301)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
历史上的今天:
2020-11-04 DESeq2中estimateSizeFactorsForMatrix源码学习
2020-11-04 安装monocle包
2020-11-04 在ubuntu上安装Rstudio笔记
2018-11-04 Wilcoxon符号秩+秩和检验学习[转载]
点击右上角即可分享
微信分享提示