Creates a file stream for input.
basic_ifstream();
explicit basic_ifstream
(const char *s, ios_base::openmode mode = ios_base::in);
The constructor creates a stream for file input. It is overloaded to either create and initialize when called or to simply create a class and be opened using the open() member function. The default opening mode is ios::in. See basic_filebuf::open() for valid open mode settings.
See basic_ifstream::open for legal opening modes.
basic_ifstream::open() for overloaded form usage.
// The ewl-test file contains: // CodeWarrior "Software at Work" #include <iostream> #include <fstream> #include <cstdlib> char inFile[] = "ewl-test"; int main() { using namespace std; ifstream in(inFile, ios::in); if(!in.is_open()) {cout << "can't open input file"; exit(1);} char c ='\0'; while(in.good()) { if(c) cout << c; in.get(c); } in.close(); return 0; }
Result:
CodeWarrior "Software at Work"