Using std:fstream how to deny access (read and write) to the file

前端 未结 3 728
被撕碎了的回忆
被撕碎了的回忆 2020-11-30 11:33

How can I deny access to a file I open with fstream? I want to unable access to the file while I\'m reading/writing to it with fstream?

3条回答
  •  旧时难觅i
    2020-11-30 11:58

    Expanding on the comment by Casebash:

    To open a file in windows so that other processes cannot write to it use

    file.rdbuf()->open(path, std::ios_base::app, _SH_DENYWR);
    

    _SH_DENYRW will deny both read and write access

提交回复
热议问题