Opening files in "exclusive mode"?

Discussion in 'C++' started by Dave Reid, Jun 16, 2005.

  1. Dave Reid

    Dave Reid Guest

    Hi everyone...

    I'm trying to open a text file in exclusive mode (meaning I want to
    lock out any other processes from accessing the file while I'm working with
    it).

    Here's my code:

    ifstream fs_infile("field_summary.dat", filebuf::sh_none)

    And I get the following error:

    'sh_none' is not a member of type 'filebuf'

    What am I doing wrong? Is this the right way to do this? Or is
    there a better way to do this file locking?

    Thanks in advance...

    Dave Reid
    Dave Reid, Jun 16, 2005
    #1
    1. Advertising

  2. Dave Reid

    Kristo Guest

    Dave Reid wrote:
    > Hi everyone...
    >
    > I'm trying to open a text file in exclusive mode (meaning I want to
    > lock out any other processes from accessing the file while I'm working with
    > it).
    >
    > Here's my code:
    >
    > ifstream fs_infile("field_summary.dat", filebuf::sh_none)
    >
    > And I get the following error:
    >
    > 'sh_none' is not a member of type 'filebuf'
    >
    > What am I doing wrong? Is this the right way to do this? Or is
    > there a better way to do this file locking?
    >
    > Thanks in advance...


    Your compiler is right. 'sh_none' is not a member of type filebuf.
    Opening a file in "exclusive mode" is likely OS-specific. Perhaps you
    could ask about it in a newsgroup dedicated to your OS.

    Kristo
    Kristo, Jun 16, 2005
    #2
    1. Advertising

  3. Dave Reid

    Stephen Howe Guest

    > I'm trying to open a text file in exclusive mode (meaning I want to
    > lock out any other processes from accessing the file while I'm working
    > with
    > it).


    No such thing according standard C++.

    You want to poke around your compilers documentation and see if they provide
    an extension or a means by which you can open in excusive mode.

    And/Or post something to your compiler-vendors newsgroups or mailing list.
    comp.lang.c++ is no good for this.

    Stephen Howe
    Stephen Howe, Jun 17, 2005
    #3
  4. Dave Reid

    PraveenAyinikkal

    Joined:
    Nov 9, 2006
    Messages:
    3
    Use Mutex for exclusive operation
    PraveenAyinikkal, Nov 9, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brad Smallridge

    Opening two files

    Brad Smallridge, Mar 28, 2005, in forum: VHDL
    Replies:
    2
    Views:
    494
    info_
    Mar 28, 2005
  2. Ashak
    Replies:
    3
    Views:
    398
    Ashak
    Aug 28, 2003
  3. Monkey Magic
    Replies:
    4
    Views:
    719
    Boudewijn Dijkstra
    Feb 6, 2004
  4. Soren
    Replies:
    9
    Views:
    469
    Knute Johnson
    Dec 5, 2006
  5. fniles
    Replies:
    0
    Views:
    256
    fniles
    Apr 26, 2009
Loading...

Share This Page