首页 > 其他 > 详细

流随机访问

时间:2014-09-03 19:38:37      阅读:192      评论:0      收藏:0      [点我收藏+]

17.39

#include<iostream>
#include<fstream>
#include<string>
#include<cstdlib>
using namespace std;

int main()
{
    fstream inOut("copyOut",fstream::ate|fstream::in|fstream::out);
    if(!inOut)
    {
        cerr<<"Unable to open file!"<<endl;
        return EXIT_FAILURE;
    }
    auto end_mark=inOut.tellg();
    inOut.seekg(0,fstream::beg);
    size_t cnt=0;
    string line;
    while(inOut&&inOut.tellg()!=end_mark&&getline(inOut,line))
    {
        cnt+=line.size()+1;
        auto mark=inOut.tellg();
        inOut.seekp(0,fstream::end);
        inOut<<cnt;
        if(mark!=end_mark)
            inOut<<" ";
        inOut.seekg(mark);
    }
    inOut.seekp(0,fstream::end);
    inOut<<\n;
    return 0;
}

 

流随机访问

原文:http://www.cnblogs.com/wuchanming/p/3954317.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!