如何允许其他程序在使用fopen和fwrite进行写入的同时读取文件?

问题描述 投票:0回答:1

我正在打开要创建的视频的文件,并使用C ++中的fopen打开文件并将其写入磁盘,我可以将其写入磁盘。但是,当我尝试在编写文件时读取它时,它会抛出错误,表明我没有在关闭文件或停止程序后立即读取文件的权限,因此可以突然读取它。 >

[没有像我使程序崩溃那样完成写操作的问题,仍然可以读取它。另外,VLC的日志告诉我这是一个权限问题。

任何想法如何更改该权限?

响应William询问代码片段,或者打开是否在文件存在之前发生:

Thanks William, here's what I've got. I waited a few minutes and could see the file with windows explorer by that point and waited until after I'd flushed and data was there, couldn't open with VLC or Notepad++ or Notepad or Windows Media Player

Notepad says cannot access because it is being used by another process, others too.
Here is the VLC log while it tries to open this:
http://snippi.com/s/g4cbu23

Here is where I create the file with fopen:
http://snippi.com/s/cyajw4h

At the very end is where I write to the file using fwrite and flush:
http://snippi.com/s/oz27m0g

我正在打开要创建的视频的文件,并使用C ++中的fopen打开文件并将其写入磁盘,我可以将其写入磁盘。但是,当我尝试在编写本书时阅读它时,它会抛出错误,指出它不是...

c++ fopen
1个回答
1
投票

如果要共享文件,则需要将_fsopen_fsopen一起使用。

© www.soinside.com 2019 - 2024. All rights reserved.