ITeye博客

fstream 文件流 操作

gryphone · 2010-05-06 11:56 · c program · 编程语言 · Markdown

文件流 借助与 fstream

 

 

 

1. 示例代码

 

#include <iostream.h> 
#include <fstream.h> 

using namespace std;

int main()
{
   ofstream data;
   
   data.open("./data.txt");
   
   if(!data.is_open()){
    cout << "couldnot open ./data.txt" << endl;
   }
   
   data <<"Hello ofstream"<<endl;
   
   data << "line 1:" << "it's line 1, griffin!" << endl;
   
   data << "line 2:" << "25, from Jiangsu." << endl;
   
   data.close();
   
   return 0;
}



 

 

2. 运行后 就会在代码目录发现文件:data.txt 内容如下:

 

Hello ofstream
line 1:it's line 1, griffin!
line 2:25, from Jiangsu.

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。