Opening a file in non exclusive mode using streams.

This is a discussion on Opening a file in non exclusive mode using streams. within the C++ Programming forums, part of the General Programming Boards category; I have searched and searched and can't seem to find a way using the C++ standard stream libraries to open ...

  1. #1
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094

    Opening a file in non exclusive mode using streams.

    I have searched and searched and can't seem to find a way using the C++ standard stream libraries to open a file in non exclusive mode so that I can read from it while it is being written to. I have found ways using C file I/O but I prefer to use streams when I possibly can, so I defer to the more knowledgable to see if there is a way before I start looking for alternative libraries, (C or Boost I am thinking)

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    There is no way to do this. C++ doesn't have such a concept. It's only Win32 that does. It works in the C API only by either platform-specific extensions to the mode string or a way of wrapping a native handle into a FILE*.

    For what it's worth, on Linux, files are always opened non-exclusive. You have to jump through a few hoops to lock a file against concurrent access.

    Boost doesn't have a library that can do this.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Hmm, then I will have to find a platform specific extension, I know it is possible because there are a fair amount of parsers for active log files, though I don't know if they are written in C++ or not, but it is worth a shot I guess. Trying to parse a file that at times is updated 5 times in a second (Everquest log file) for a friend since he needs something to keep track of who is looting what and categorize the loots so he can take the good stuff for the guild bank for all to use.

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by Wraithan View Post
    I have searched and searched and can't seem to find a way using the C++ standard stream libraries to open a file in non exclusive mode so that I can read from it while it is being written to. I have found ways using C file I/O but I prefer to use streams when I possibly can, so I defer to the more knowledgable to see if there is a way before I start looking for alternative libraries, (C or Boost I am thinking)
    You want to read AND write to the same stream? Use an fstream.

  5. #5
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Isn't this what the tail command is for in *nix?

  6. #6
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Brewbuck: Nah I am not writing to the stream, I am only reading it. An external program is writing to it, I just want to continuously grab anything added to the file so I can parse for certain events.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  2. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  3. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  4. Saving with CFile (how)
    By jinx in forum Windows Programming
    Replies: 1
    Last Post: 10-18-2001, 09:19 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21