Shareing Files in C++

how can i make file share in c++ fstream?
and not be the _FSOPEN or SOPEN.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

In the third parameter to either the constructor or the open() function, you specify one of the following:

filebuf::openprot, which is equivalent to the operating system default, filebuf::sh_compat, under MS-DOS. The possible nProt values are as follows:
filebuf::sh_compat   Compatibility share mode (MS-DOS only).
filebuf::sh_none   Exclusive mode — no sharing.
filebuf::sh_read   Read sharing allowed.
filebuf::sh_write   Write sharing allowed.

let me know if this solves what you're asking
This is the way the stream buf use sopen inside the CRT source:


void fstream::open(const char * name, int mode, int prot)
    if (is_open() || !(rdbuf()->open(name, mode, prot)))
        istream::clear(istream::state | istream::failbit);
        ostream::clear(ostream::state | ostream::failbit);

****where share is equalt to the prot param used upper
**** as an arg for  fstream::open

    share &= (sh_read|sh_write|sh_none); // ignore other bits
    if (share)  // optimization  openprot serves as default
        switch (share)
/*          case 03000 : Reserved for sh_compat  */

//          case sh_none :
            case 04000 :
                smode = _SH_DENYRW;
//          case sh_read :
            case 05000 :
                smode = _SH_DENYWR;
//          case sh_write :
            case 06000 :
                smode = _SH_DENYRD;
//          case (sh_read|sh_write) :
            case 07000 :
                smode = _SH_DENYNO;
            default :   // unrecognized value same as default

    x_fd = _sopen(name, dos_mode, smode, S_IREAD|S_IWRITE);


So using:
filebuf::sh_none is equal to SOPEN _SH_DENYRW;
filebuf::sh_read is equal to SOPEN  _SH_DENYWR;
filebuf::sh_write is equal to SOPEN _SH_DENYRW;
filebuf::sh_read|filebuf::sh_write is equal to SOPEN  _SH_DENYNO;

I think that's all the information you need to know!


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.