C++バイナリファイル書き込み操作
5110 ワード
#include<fstream.h>
main()
{
int a[10]={0};
for(int i=0;i<9;i++)
{
a[i+1]=a[i]*10+i+1;
cout<<a[i]<<endl;
}
ofstream rs("ok2002com.bin",ios::binary);// ok2002com.bin; : , :ios::binary
for(i=0;i<9;i++)
{
rs.write((char*)(&a[i]),sizeof(a[i]));// ok2002com.bin
cout<<"rs.tellp("<<i<<")="<<rs.tellp()<<endl;//
}
rs.close();
cin>>i;
}
* :
-----------------------------
0
1
12
123
1234
12345
123456
1234567
12345678
rs.tellp(0)=2, rs.tellp(0)=4
rs.tellp(1)=4, rs.tellp(1)=8
rs.tellp(2)=7, rs.tellp(2)=12
rs.tellp(3)=11, rs.tellp(3)=16
rs.tellp(4)=16, rs.tellp(4)=20
rs.tellp(5)=22, rs.tellp(5)=24
rs.tellp(6)=29, rs.tellp(6)=28
rs.tellp(7)=37, rs.tellp(7)=32
rs.tellp(8)=46, rs.tellp(8)=36
-----------------------------
● :
1、
, , ( ) ;
2、
, , 。
●
(1) ;
(2) ;
(3) ;
(4) ;
(5) ;
● :
(1) ;
(2) , 、 ;
● ? ?
, 。
● ? ?
: 、 、 ; : ;
: 、 、 。 : ;
: , , : , , 。
●C++ tellp() tellg()
tellp() “ ” ( );
tellg() “ ” ( )。