【问题标题】:fclose does not close audio filefclose 不关闭音频文件
【发布时间】:2019-12-18 23:51:34
【问题描述】:

我有以下 C++ 代码将短片写入无头音频文件:

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);

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

一旦命中这个断点,我就会尝试使用 Windows 资源管理器删除这个文件。这应该可以工作,因为文件已经使用“fclose”关闭了。

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

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

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

【问题讨论】:

  • 如果您在调用fopen之前尝试将其删除,是否有效?
  • 您确定您使用的调试器在执行您设置断点的行后会停止程序吗?在之后写一个printf 并在其上设置一个断点。
  • 你确定你真的在打开文件吗?你从不检查文件指针

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


【解决方案1】:

我找到了罪魁祸首:

我在 parallel_for 中运行它。

这就解释了一切。 :-)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-13
    • 1970-01-01
    • 2012-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多