different forms of the fstream constructors ifstream fa(filename); ifstream fb(filename, flags); ofstream fc(filename); ofstream fd(filename, flags); fstream fe(filename); fstream ff(filename, flags); filename must be an old-fashioned C string (or a "string literal"). flags is any combination (using the bitwise or | operator) of ios::in - open for reading ios::out - open for writing ios::binary - when it is not a text file ios::trunc - erase content of file if it already exists ios::app - all output is appended to the end of the file If you do not provide any flags along with the filename, the defaults are for ifstream - ios::in for ofstream - ios::out | ios::trunc for fstream - ios::in | ios::out If you do provide flags, of course the default is ignored. If you use ofstream without specifying ios::trunc, the original contents of the file (if there are any) are not erased. Alternatively ifstream fg; ofstream fh; fstream fi; followed later by fg.open(filename, flags); To read non-text data: fa.read(pointer, number); pointer is a pointer to any variable, array, or struct. The bytes read from the file will be written directly where that pointer points. Remember to typecast to (char *). number is the number of bytes to read. After using read, it is a good idea to use gcount: int n = fa.gcount(); n is the number of bytes that were successfully read by the last read() done. It will be less than the number requested if the end of the file is reached. To write non-text data: fc.write(pointer, number); Don't forget to close files when finished with them. Current position in the file: int p = fa.tellg(); // for input streams int q = fc.tellp(); // for output streams these return the current position in the file, the value is the number of bytes from the beginning. If you have only just opened the file, the position will be zero. fa.seekg(p, relative); // input fc.seekp(p, relative); // output these are used to change the position in the file, so that earlier data can be re-read (or overwritten) or so that you can skip over data that you do not need to read. "relative" must be one of the three constants ios::beg, ios::cur, ios::end. ios::beg (beginning) - reposition to exactly p bytes from the beginning of the file ios::cur (current) - reposition p bytes from the current position, so a positive p means p bytes will be skipped, p can be negative. ios::end - reposition to p bytes beyond the end of the file, p=0 is the most common: go directly to the end of the file, but p may be negative.