首页 文章

std :: fstream不会打开当前进程的文件,但是open()会吗?

提问于
浏览
0

我试图打开当前进程的可执行文件进行读写操作(我有附加到可执行文件的附加数据),但是std :: fstream不会在ios :: in中打开文件 . ios :: out | ios :: binary模式,即使open()也会(设置O_RDWR标志) .

有谁知道为什么std :: fstream不会打开文件,而open()会,如果是这样,我怎么能让std :: fstream打开文件?

2 回答

  • 0

    它很可能与文件共享语义有关 . 见this thread处理类似的问题 - 答案是"The concept of file protection, file sharing, file permissions is OS-specific, which is why it is not covered by standard C++" .

  • 1

    我想知道,在某个地方,引擎盖下, std::fstream 版本是否正在调用 open - 我敢打赌 . 您是否尝试过检查errno,或者运行 strace 以查看系统调用返回的是什么错误?

相关问题