Hi,
I was wondering why there are file access modes, which you have to
specify when opening the file. I am specifically talking about the 'read',
'read-write' and 'write' distinction. As far as I can tell, it only makes
sure, you (the programmer) do not accidently write to it when you opened it
for reading. To me, this seems like another one of those things that just
make life harder.
I am asking this, because I am writing a wrapper (not *just* a wrapper,
tho) for file operations with files on a hard disk. Should I provide those
different flags as well? If so, what for? Why don't I just let the user of
the code 'open' the file and read and write to it as she wishes?
Thanks!
--
jb
(replace y with x if you want to reply by e-mail) 6 2043
"Jakob Bieling" <ne*****@gmy.net> wrote... I was wondering why there are file access modes, which you have to specify when opening the file. I am specifically talking about the 'read', 'read-write' and 'write' distinction. As far as I can tell, it only makes sure, you (the programmer) do not accidently write to it when you opened
it for reading. To me, this seems like another one of those things that just make life harder.
AFAIK, there are platforms that allow to simultaneously open the same
file for reading by more than one process. Simultaneous writing is
not allowed on those systems. So, if you open for write or read-write
a file that is being read by another process, the operation will fail.
Since those OS traits are not standardised, C++ cannot make any real
claims about it, but it provides some kind of mechanism that would be
functioning if such abilities exist. Basically, the same as with text
and binary modes. For Unices it makes no difference, for DOS and Win
it does.
I am asking this, because I am writing a wrapper (not *just* a
wrapper, tho) for file operations with files on a hard disk. Should I provide those different flags as well?
Certainly.
If so, what for?
For flexibility.
Why don't I just let the user of the code 'open' the file and read and write to it as she wishes?
Because it may not be what the user wants. Why castrate functionality
when it's not that difficult to simply delegate it?
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:AU6zb.396577$HS4.3207826@attbi_s01... "Jakob Bieling" <ne*****@gmy.net> wrote... I was wondering why there are file access modes, which you have to specify when opening the file. I am specifically talking about the
'read', 'read-write' and 'write' distinction. As far as I can tell, it only
makes sure, you (the programmer) do not accidently write to it when you opened it for reading. To me, this seems like another one of those things that
just make life harder.
AFAIK, there are platforms that allow to simultaneously open the same file for reading by more than one process. Simultaneous writing is not allowed on those systems. So, if you open for write or read-write a file that is being read by another process, the operation will fail.
Since those OS traits are not standardised, C++ cannot make any real claims about it, but it provides some kind of mechanism that would be functioning if such abilities exist. Basically, the same as with text and binary modes. For Unices it makes no difference, for DOS and Win it does.
I am asking this, because I am writing a wrapper (not *just* a wrapper, tho) for file operations with files on a hard disk. Should I provide
those different flags as well?
Certainly.
If so, what for?
For flexibility.
Why don't I just let the user of the code 'open' the file and read and write to it as she wishes?
Because it may not be what the user wants. Why castrate functionality when it's not that difficult to simply delegate it?
Hi Victor,
thanks a lot for your quick reply! I guess you come to ask those kind of
questions when you only live in your little Windows world ;) Looks like
I'll go thru the little work and provide the distiction when opening.
Regards
--
jb
(replace y with x if you want to reply by e-mail)
Jakob Bieling wrote: I was wondering why there are file access modes, which you have to specify when opening the file. I am specifically talking about the 'read', 'read-write' and 'write' distinction. As far as I can tell, it only makes sure, you (the programmer) do not accidently write to it when you opened it for reading. To me, this seems like another one of those things that just make life harder.
I am asking this, because I am writing a wrapper (not *just* a wrapper, tho) for file operations with files on a hard disk. Should I provide those different flags as well? If so, what for? Why don't I just let the user of the code 'open' the file and read and write to it as she wishes? ...
In addition to Victor's reply I'd like to add that there are other
reasons to specify these modes when opening a file. For example, in many
cases on many platforms file I/O is cashed in memory. The cashing can be
organized more efficiently if it is known that the file will be used for
reading (or writing) only.
--
Best regards,
Andrey Tarasevich
Andrey Tarasevich wrote: I was wondering why there are file access modes, which you have to specify when opening the file. I am specifically talking about the 'read', 'read-write' and 'write' distinction. As far as I can tell, it only makes sure, you (the programmer) do not accidently write to it when you opened it for reading. To me, this seems like another one of those things that just make life harder.
I am asking this, because I am writing a wrapper (not *just* a wrapper, tho) for file operations with files on a hard disk. Should I provide those different flags as well? If so, what for? Why don't I just let the user of the code 'open' the file and read and write to it as she wishes? ...
In addition to Victor's reply I'd like to add that there are other reasons to specify these modes when opening a file. For example, in many cases on many platforms file I/O is cashed in memory. The cashing can be organized more efficiently if it is known that the file will be used for reading (or writing) only.
I meant "cached", not "cashed" :)
--
Best regards,
Andrey Tarasevich
Victor Bazarov wrote: "Jakob Bieling" <ne*****@gmy.net> wrote... I was wondering why there are file access modes, which you have to specify when opening the file. I am specifically talking about the 'read', 'read-write' and 'write' distinction. As far as I can tell, it only makes sure, you (the programmer) do not accidently write to it when you opened it for reading. To me, this seems like another one of those things that just make life harder.
AFAIK, there are platforms that allow to simultaneously open the same file for reading by more than one process. Simultaneous writing is not allowed on those systems. So, if you open for write or read-write a file that is being read by another process, the operation will fail.
And further more, some operating systems can give users different rights
for reading and writing files, so they are allowed to write only to
files that they created themselves or that they are explicitly allowed
to write to, but are allowed to read many other files. In fact, those
access restrictions belong to the most basic and important features of
many modern OSs.
"Jakob Bieling" <ne*****@gmy.net> wrote in message
news:bq*************@news.t-online.com... Hi,
I was wondering why there are file access modes, which you have to specify when opening the file. I am specifically talking about the 'read', 'read-write' and 'write' distinction. As far as I can tell, it only makes sure, you (the programmer) do not accidently write to it when you opened
it for reading. To me, this seems like another one of those things that just make life harder.
No, usually it's so other code doesn't accidentally write to it. When
someone else tries to open that file, they might want exclusive access, or
not want to mess with it while someone else has write access to it instead
of just read access. That could really screw up certain operations. Also,
some files are read only. That protects the file itself from a program
opening it with write access. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Karthikesh Raju |
last post by:
Hi All,
i am wondering about the best way to read in a configuration file that
goes like:
###########
source_dir = '/home/karthik/Projects/python'
data_dir =...
|
by: pxlpluker |
last post by:
What exactly does the underlined text mean. w & a obviously mean you are
going to update the file.
So what does the + mean on w+ & a+ mean?
Also please could someone explain w+ truncating the...
|
by: Brandon McCombs |
last post by:
This may be the wrong group but I didn't see anything for VC++ so I'm
trying here.
I have a C++ book by Deitel and Deitel that says I can use fstream
File("data.dat", ios::in | ios::out |...
|
by: Tom |
last post by:
I am having trouble when I read a file and another process
is trying to update it.
So I need a rountine to copy a file in asp.net.
Can anyone assist?
Thanks
Tom
|
by: David Warner |
last post by:
Greetings!
I am working on a C app that needs to read print files generated by lp
that contain HP LaserJet PCL codes. If the PCL contains binary data to
define a bit map to be printed on the...
|
by: erikcw |
last post by:
Hi all,
I've created a script that reads in a file, replaces some data (regex),
then writes the new data back to the file.
At first I was convinced that "w+" was the tool for the job. But now...
|
by: HMS Surprise |
last post by:
After reading a file is it possible to write to it without first
closing it? I tried opening with 'rw' access and re-winding. This does
not seem to work unless comments are removed.
Also, does...
|
by: rory |
last post by:
I can't seem to append a string to the end of a binary file. I'm using
the following code:
fstream outFile("test.exe", ios::in | ios::out | ios::binary |
ios::ate | ios::app)...
|
by: |
last post by:
Hi,
I need to get the the display monitor native resolution.I have tried
SystemInformation.PrimaryMonitorSize. it is giving the exisiting resolution
of the display monitor that is connected....
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |