我有以下 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 告诉我“文件正在使用中:该操作无法完成,因为该文件正在被其他程序使用”:
因为我不认为这是真的,所以我启动了 LockHunter。 LockHunter 告诉我以下内容:
有人知道这种奇怪的行为可能是由什么引起的吗?
最佳答案
我找到了罪魁祸首:
我在 parallel_for 中运行它。
这说明了一切。 :-)
关于c++ - fclose 不关闭音频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59401556/