PRODUCT : Borland C++ NUMBER : 1161 VERSION : 3.1 OS : ALL DATE : October 19, 1993 PAGE : 1/2 TITLE : Using C++ streams with shared files. How to Open a File in Shared Mode Using Streams The following example shows how to use streams with files which must be opened in SHARED mode. The basic idea is to create a stream that uses the file handle that was obtained from sopen() [ i.e. the handle to a shared file ]. #include #include #include #include #include #include #include #include const int BUFSIZE = 80; const char fname[15] = "c:\\delete.me"; void main( void ) { int handle; char buffer[BUFSIZE]; // First we need to open a file using sopen(). handle = sopen( fname, O_CREAT | O_RDWR, SH_DENYNO, S_IREAD | S_IWRITE ); if ( !handle ) { printf( "sopen() failed\n" ); exit( 1 ); } fstream cppstream( handle ); // input and output cppstream.write( "This file is open for sharing\n", 31 ); PRODUCT : Borland C++ NUMBER : 1161 VERSION : 3.1 OS : ALL DATE : October 19, 1993 PAGE : 2/2 TITLE : Using C++ streams with shared files. cppstream.seekg( 0L, ios::beg ); // go to beginning cppstream.getline( buffer, BUFSIZE );// get first line cout << buffer; // write the line to the screen close( handle ); } DISCLAIMER: You have the right to use this technical information subject to the terms of the No-Nonsense License Statement that you received with the Borland product to which this information pertains.