C++中fstream如何判断文件不存在

如题...
2026年09月19日 22:53
有2个网友回答
网友(1):

#include
#include
using namespace std;
#define FILENAME "D:\\aaa.txt"
int main()
{
fstream file;
file.open(FILENAME,ios::in);
if(!file)
{
cout< }
else
{
cout< }
return 0;
}
}

网友(2):

以std::ios::in方式打开文件。打开失败就是不存在