第二十一章流 12输出数据到文件指定位置处seekp()

//第二十一章流 12输出数据到文件指定位置处seekp()

//想要在文件指定位置处输出数据,那么fstream类的seekp()成员函数可以为我们达到目的

/*#include <iostream>

#include <fstream>

using namespace std;

int main()

{

	ofstream fout("people.txt");

	if(!fout){

	   cout<<"创建文件失败"<<endl;

	}

	fout<<"ABCDEFGLIJKLMIOPQ";

	fout.close();



	//这里创建fstream类对而不是ostream类对像进行输出操作原因,是因为ostream类的对像在默认情况下要开一个文件时会自动清空该文件的数据进行输出操作

	fstream fout1;

	fout1.open("people.txt");

	char ch[] = "123456789";

	fout1.seekp(9,ios::beg); //写入到指定的位置

	fout1<<ch;

	fout1.close();

	

	ifstream fin("people.txt");

	if(fin.fail())

	{

	   cout<<"打开文件失败"<<endl;

	}

	char ch1;

	while(fin.get(ch1)){

	   cout<<ch1;

	}

	fin.close();

    return 0;

}*/

  

你可能感兴趣的:(文件)