How to check if a file exists and is readable in C++?

前端 未结 8 1468
时光说笑
时光说笑 2020-12-13 12:19

I\'ve got a fstream my_file(\"test.txt\"), but I don\'t know if test.txt exists. In case it exists, I would like to know if I can read it, too. How to do that?

I

8条回答
  •  感情败类
    2020-12-13 12:42

    What Operating System/platform?

    On Linux/Unix/MacOSX, you can use fstat.

    On Windows, you can use GetFileAttributes.

    Usually, there is no portable way of doing this with standard C/C++ IO functions.

提交回复
热议问题