To construct an object of basic_ifstream for input and output operations.
basic_fstream();
explicit basic_fstream (const char *s, ios_base::openmode = ios_base::in | ios_base::out);
The basic_fstream class is derived from basic_iostream and a basic_filebuf object is initialized at construction.
// The ewl-test file contains originally // CodeWarrior "Software at Work" #include <iostream> #include <fstream> #include <cstdlib> char inFile[] = "ewl-test"; int main() { using namespace std; fstream inOut(inFile, ios::in | ios::out); if(!inOut.is_open()) {cout << "Could not open file"; exit(1);} char str[] = "\n\tRegistered Trademark"; char ch; while((ch = inOut.get())!= EOF) { cout << ch; } inOut.clear(); inOut << str; inOut.close(); return 0; }
Result:
CodeWarrior "Software at Work"
The File now reads:
CodeWarrior "Software at Work"
Registered Trademark