ifstream::ifstream
[constructor] ifstream ( ); explicit ifstream ( const char * filename, openmode mode = in ); | ifstream |
cplusplus.com |
Construct an object and optionally open a file.
Constructs an object of class ifstream. This implies the initialization of the
associated filebuf object and the call to its base class' constructor with the
filebuf object as constructor parameter.
Additionally, in case the second constructor syntax is used, the stream's file is associated
with a physical file as if a call to member open
with the same parameters was made.
Parameters.
bit effect app (append) Seek to the end of the stream before each output operation. ate (at end) Seek to the end of the stream when opening. binary Consider stream as binary rather than text. in Allow input operations on a stream. out Allow output operations on a stream. trunc (truncate) Truncate file to zero when opening.
Return Value.
none
Example.
// using ifstream constructors.
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ifstream infile ("test.txt");
while (infile.good())
cout << (char) infile.get();
infile.close();
return 0;
}
This example opens a file and prints its content to the standard output device.
Basic template member declaration ( basic_ifstream<charT,traits> ):
basic_ifstream(); explicit basic_ifstream ( const char * filename, openmode mode = in ); |
See also.
open
ifstream class