64,282
社区成员
发帖
与我相关
我的任务
分享
#include "io.h"
bool is_file_exist(const char* pcsFile)
{
return pcsFile!=NULL && access(pcsFile, 0)==0;
}
#include <iostream>
#include <fstream>
using namespace std;
#define FILENAME "stat.dat"
int main()
{
fstream _file;
_file.open(FILENAME,ios::in);
if(!_file)
{
cout<<FILENAME<<"没有被创建";
}
else
{
cout<<FILENAME<<"已经存在";
}
return 0;
}
//忽略5L
ios::nocreate: 不建立文件,所以文件不存在时打开失败
#include <iostream>
#include <fstream>
using namespace std;
void main()
{
ofstream file( "aaa.txt" );
if( file )
{
cout << "if( file ) " << endl;
}
if(file.is_open())
{
cout << "file.is_open()" << endl;
}
file.close();//
}
#include <iostream>
#include <fstream>
using namespace std;
void main()
{
ofstream file( "aaa.txt" );
if( file )
{
cout << "if( file ) " << endl;
}
if(file.is_open())
{
cout << "file.is_open()" << endl;
}
file.close();//放开它后,为什么输入的内容写不到文件中去.
}