filebuf* rdbuf() const;
Returns a pointer to the filebuf buffer object that is associated with this stream. (Note that this is not the character buffer; the filebuf object contains a pointer to the character area.)
extern ofstream ofs;
int fd = ofs.rdbuf()->fd(); // Get the file descriptor for ofs