C++ファイル読み書き操作
1511 ワード
C++ファイルフロー
fstream //
ifstream //
ofstream //
:
ios::in // , (ifstream )
ios::out // , , (ofstream )
ios::ate // , 。 , in、out
ios::app // , , ,
ios::trunc // 0( )
ios::nocreate // , in app
ios::noreplace // , out
ios::binary //
:
filebuf::openprot; //
filebuf::sh_none; // ,
filebuf::sh_read; //
filebuf::sh_write; //
fstream f("d:\\12.dat",ios::in|ios::out|ios::binary); //
Open
fstream f;
f.open("d:\\12.txt",ios::out); // open
:
if(f){...} // ifstream、ofstream ,fstream 。
if(f.good()){...}
:
if(!f){...} // !
if(f.fail()){...}
, 。
seekg( ); // ,
seekg( , ); //
tellg(); //
seekp( ); // ,
seekp( , ); //
tellp(); //
:
ios::beg = 0 //
ios::cur = 1 //
ios::end = 2 //
continued……