c++ - fclose 不关闭音频文件

标签 c++ windows file visual-studio-2019

我有以下 C++ 代码来将 shorts 写入 headless 音频文件:

vector<short>nShrtDecoded;
nShrtDecoded.resize(iCountDecodedShorts);//-1

//Then I fill the vector of short with some audio. I didn't write that length code here. I think it doesn't matter anyway HOW exactley I fill this vector of shorts

FILE* outfile = fopen("d:\\!wavs\\weg.raw", "wb");
fwrite(&nShrtDecoded[0], sizeof(short), nShrtDecoded.size(), outfile);
fclose(outfile);

我在 Debug模式下运行此代码,并在“fclose(outfile)”行之后的行中设置了一个断点。

一旦命中此断点,我就尝试使用 Windows 资源管理器删除此文件。这应该有效,因为该文件已使用“fclose”关闭。

当我尝试删除文件“d:\!wavs\weg.raw”时,Windows 告诉我“文件正在使用中:该操作无法完成,因为该文件正在被其他程序使用”:

enter image description here

因为我不认为这是真的,所以我启动了 LockHunter。 LockHunter 告诉我以下内容:

enter image description here

有人知道这种奇怪的行为可能是由什么引起的吗?

最佳答案

我找到了罪魁祸首:

我在 parallel_for 中运行它。

这说明了一切。 :-)

关于c++ - fclose 不关闭音频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59401556/

相关文章:

c# - 在 C# 中预分配文件空间?

c++ - 指针和结构导致段错误

c++ - 为什么我将函数命名为 `swap` 时会出现模板错误,但 `Swap` 没问题?

file - 将矩阵写入文件,没有标题和行号

c++ - 如何在普通用户环境中以编程方式隐藏 Windows 8 上的任务栏?

windows - 远程窗口上临时文件夹的位置

ruby - 在子目录的文件中搜索字符串

c++ - 以无符号整数存储缓冲区地址;

c++ - 内存使用比较

java - Titanium Studio - Java 返回错误 13