bool good(void)
- true if no errors; false otherwise
ifstream inf; const string fname = "my.dat"; inf.open(fname.c_str()); if (!inf.good()) cerr << "Can't open " << fname << "\n";
inf.read(data, data_size); if (inf.eof()) // whatever if (!inf.good()) // whatever
bool operator!(stream)
returns true if there are no errors
operator!
doesn't consider eof an error
ifstream inf; const string fname = "my.dat"; inf.open(fname.c_str()); if (!inf) cerr << "Can't open " << fname << "\n";
good()
over operator!
open()
describes how the file should be
opened
ios::in
- open for reading, file pointer at the beginning of the
file
ios::out
- open for writing, file pointer at the beginning of
the file; this trashes the previous file contents
ios::app
- open for writing (appending), file pointer at the end
of the file; this preserves the previous contents of the file
ifstream
s is ios::in
ofstream
s is ios::out
- the default open
for writes is destructive
fstream
s have no defaults - you must specify ios::in
,
ios::out
, or ios::in + ios::out
open()
ifstream inf("my.dat");
void put(char)
file stream member function
int get(void)
file stream member function
getline(ifstream, string)
function
<string>
, not in the stream includes
This page last modified on 23 July 2001.