TITLE: Getting file descriptors from fstream PROBLEM: morss@ssd.kodak.com (Charlie Morss) I recently asked a question in regard to record locking using the fstream class. Steve Clamage replied and suggested that I derive a class from fstream called lfstream in which I could then have a lock and unlock member function. Now the question is how do you get the file descriptor from the fstream class? RESPONSE: steve@taumet.com (Steve Clamage) Vice Chair, ANSI C++ Committee, X3J16 Check . Class filebuf usually has a member function fd() which returns the file descriptor. This is all rather specific to Unix-like implementations. If you are trying to do file locking on a radically different system, there may be slightly different functions. Presumably the filebuf class provides some way to get at the underlying file in a way consistent with the file locking routines. Example: #include main() { fstream f("foo.bar", ios::in|ios::out); // use fstream::rdbuf() to get the filebuf // then filebuf::fd() to get the file descriptor cout << "file descriptor = " << (f.rdbuf())->fd() << endl; return 0; }