zoukankan      html  css  js  c++  java
  • 第二十一章流 11指定读取文件中的数据seekg() 简单

    //第二十一章流 11指定读取文件中的数据seekg()
    //假如我们不想全部读入文件中的数据,而是只读取其中的某项数据,那么fstream类的seekg()成员函数可以为我们达到目的
    /*#include <iostream>
    #include <fstream>
    using namespace std;
    int main()
    {
    	ofstream fout("people.txt");
    	if(!fout){
    	    cout<<"创建文件失败";
    	}
    	fout<<"1234567890asfdsfasfasfasfa";
    	fout.close();
    
    	ifstream fin("people.txt");
    	if(fin.fail())
    	{
    	    cout<<"打开文件失败"<<endl;
    	}
    	//fin.seekg(9,ios::beg); //从第九个字符开始到文档的最后
    	//fin.seekg(1,ios::cur); //当前位置往文件尾称动一个字符
    	fin.seekg(10,ios::end); //从文件结尾往文件头称动10个字符
    	//fin.seekg(10,ios::end)执行不成功,不知道咱回事
    	
    	
    	//seekg()函数的第二个参数有下列几种可能的性
    	//ios::beg //相对于文件开头的偏移量
    	//ios::cur //相当于当前位置的偏移量
    	//ios::end //相当于文件结尾的偏移量
    
    	char ch;
    	while(fin.get(ch)){
    	   cout<<ch;
    	}
    	fin.close();
        return 0;
    }*/
    

      

  • 相关阅读:
    @loj
    @hdu
    @hdu
    转:sql之left join、right join、inner join的区别
    MySQL客户端Workbench
    转:js中this关键字详解
    转:jQuery弹出二级菜单
    转:ASP.NET 使用Ajax
    Python类的特点 (3) :静态方法与类方法
    Python类的特点 (2) :类属性与实例属性的关系
  • 原文地址:https://www.cnblogs.com/xiangxiaodong/p/2709702.html
Copyright © 2011-2022 走看看