I'm wondering whether making files read-only so the user can't mess with them will disallow my program from writing information to them via an fstream.
views:
108answers:
2If you open a file read-only, you can't write to it.
If you are looking to open a file that you can write to but nobody else can, then (in Windows) you are looking for file sharing attributes.
Yes. If a file is read-only, it's read-only. Why not unset the read-only bit, write to the file, and reset it? The lock that you get on the file while writing to it should prevent users from making modifications to it while your application is writing to it. However, IMHO, the whole exercise is pointless, since it takes exactly 4 clicks to make a file writable, so your users can change the file whenever they want anyway. What I'd do is make an md5 or sha1 hash of the file, store it in the registry and check to see if that's changed on application startup.