Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 操作系统 > 其他操作系统 > aCC下的fstream
【标  题】:aCC下的fstream
【关键字】:aCC,fstream
【来  源】:http://blog.chinaunix.net/article.php?articleId=19595&blogId=4353

aCC下的fstream

Your Ad Here

使用stl,就意味着告别熟悉的c-style编程方式,对文件的处理也毫不例外.

fstream可以用来对文件进行处理,它象对待数据流一样对待文件.

以下给出一个例子.关键是事先要创建fstream.out文件,哪怕是个空文件,也要先创建.因为fstream不会为你创建.

#include<iostream>
#include<fstream>
int main ( )
{
         using namespace std;

          // create a bi-directional fstream object
         fstream inout("fstream.out");

          // output characters
         inout << "Das ist die rede von einem man" << endl;
         inout << "C'est l'histoire d'un home" << endl;
         inout << "This is the story of a man" << endl;

         char p[100];

          // seek back to the beginning of the file
         inout.seekg(0);

          // extract the first line
         inout.getline(p,100);

          // output the first line to stdout
         cout << endl << "Deutch :" << endl;
         cout << p;

         fstream::pos_type pos = inout.tellg();

          // extract the second line
         inout.getline(p,100);

          // output the second line to stdout
         cout << endl << "Francais :" << endl;
         cout << p;

          // extract the third line
         inout.getline(p,100);

          // output the third line to stdout
         cout << endl << "English :" << endl;
         cout << p;

          // move the put sequence before the second line
         inout.seekp(pos);

          // replace the second line
         inout << "This is the story of a man" << endl;

          // replace the third line
         inout << "C'est l'histoire d'un home";
          // replace the third line
         inout << "C'est l'histoire d'un home";

          // seek to the beginning of the file
         inout.seekg(0);

          // output the all content of the fstream
          // object to stdout
         cout << endl << endl << inout.rdbuf();
}

string to wstring?:【上一篇】
文字编辑器--vi简介:【下一篇】
【相关文章】
  • apache  ~~~ .htaccess 的应用
  • 认识 .htaccess
  • FreeBSD 5.x File System Access Control Lists
  • .htaccess网页访问限制
  • 财务软件SQL-Ledger Accounting
  • Anonymous CVS access via ssh
  • Managing CVS access with POSIX Access Control List
  • Accessing XPath Using SAX
  • 什么是Eaccelerator?
  • eAccelerator 从源代码安装
  • 【随机文章】
  • 改变网页中图片大小的函数,双击变大,ctrl+双击变小
  • WEB标准略解(二):XHTML代码规范、CSS等
  • 软件测试:V模型问题分析
  • Cannot view some web sites when using PPPoE
  • 天堂2 20-24级的巫师练法
  • FreeBSD连载(49):进入X Window
  • Websphere的特点(2)
  • Illustrator中参考线的妙用II(2)
  • 用PHP调用Oracle存储过程
  • Java修饰词总结
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.