Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Sharing file w/ fstream


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 jesterlecodeur   Members   -  Reputation: 122

Like
Likes
Like

Posted 06 May 2002 - 08:17 PM

Is there a way to define the sharing mode of a file w/ fstream? If I make fstream f("toto.txt"); I can''t open the file w/ another process before I close f. Is there a way w/ Standart C++ (I now that the fstream MS specific can do this, but I want make it protable). _______________
Jester, studient programmer The Jester Home in French

Sponsor:

#2 Oluseyi   Staff Emeritus   -  Reputation: 1678

Like
Likes
Like

Posted 07 May 2002 - 02:06 AM

The fstream constructor takes three parameters, but two of them have default values. To specify sharing mode, simply do the following:

fstream f ( "filename.ext", ios::in|ios::out, filebuf::sh_read|filebuf::sh_write );


[ GDNet Start Here | GDNet Search Tool | GDNet FAQ ]
[ MS RTFM [MSDN] | SGI STL Docs | Boost ]
[ Google! | Asking Smart Questions | Jargon File ]
Thanks to Kylotan for the idea!


#3 jesterlecodeur   Members   -  Reputation: 122

Like
Likes
Like

Posted 07 May 2002 - 04:52 AM

The problem is:
On VC++:
sh_read and sh_write are defined on fstream.h wich seems to be Microsoft specific (not in the std namespace) and independant of fstream.
The more near in the fstream header:
explicit basic_fstream(const char *_S, ios_base::openmode _M = in | out)

On Digital UNIX V4.0D w/ gcc 2.95:
No sh_read nor sh_write in the fstream.h.
The more affialte ctor i find is :
fstream(const char *name, int mode, int prot=0664);

Maybe that I miss some header?

_______________

Jester, studient programmer
The Jester Home in French


#4 Fruny   Moderators   -  Reputation: 1653

Like
Likes
Like

Posted 07 May 2002 - 09:00 AM

The concept of file protection, file sharing, file permissions is OS-specific, which is why it is not covered by standard C++

You could always write your own file buffer class, specialised in non-locking access to files and create fstream objects which use your file buffer class.

I understand that''s not what you want to hear, but that''s the only way to do it that I can see... beside using fstream.h

[Questions (STFW) | GDNet Start Here | GDNet Search | Forum FAQ | Google | Asking Smart Questions ]
[Docs (RTFM) | MSDN | SGI''s STL | OpenGL | File formats]
[C++ Must Haves (RTFS) | MinGW | Boost | Loki | FLTK | SDL ]

Stolen from Magmai Kai Holmlor, who held it from Oluseyi, who was inspired by Kylotan...


#5 jesterlecodeur   Members   -  Reputation: 122

Like
Likes
Like

Posted 07 May 2002 - 11:08 AM

This is annoying, thx for the reply all.

_______________

Jester, studient programmer
The Jester Home in French





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS