How to check if a file exists before creating a new file

前端 未结 9 933
我寻月下人不归
我寻月下人不归 2021-01-01 10:49

I want to input some contents to a file, but I\'d like to check first if a file with the name I wish to create exists. If so, I don\'t want to create any file, even if the f

9条回答
  •  我在风中等你
    2021-01-01 11:17

    you can also use Boost.

     boost::filesystem::exists( filename );
    

    it works for files and folders.

    And you will have an implementation close to something ready for C++14 in which filesystem should be part of the STL (see here).

提交回复
热议问题