Is there a way to open the file in a non-exclusive way,
Yes, using Win32, passing various FILE_SHARE_Xxxx flags to CreateFile.
is it a cross platform?
No, this requires platform-specific code.
Due to annoying backward compatibility (DOS applications, being single-tasking, assume that nothing can remove a file from under them, i.e. that they can fclose () and then fopen () without any changes, Win16 saved this assumption is to facilitate the transfer of DOS applications, Win32 has retained this assumption to simplify the transfer of Win16 applications, and this is terrible), Windows by default opens files exclusively.
The main OS infrastructure supports deleting / renaming open files (although I believe that it has a restriction that memory mapped files cannot be deleted, which, I think, is not a restriction on * nix), but the default semantics of opening are do not do it.
C ++ has no idea about this; The C ++ operating environment is almost the same as the DOS operating environment - no other applications running at the same time, so there is no need to control file sharing.
source share