//第二十一章流 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;
}*/

  

相关文章:

  • 2021-05-28
  • 2021-05-24
  • 2021-05-31
  • 2021-11-17
  • 2021-09-16
  • 2021-11-23
  • 2021-06-09
  • 2022-12-23
猜你喜欢
  • 2022-01-13
  • 2021-07-26
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2021-11-23
相关资源
相似解决方案