#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include <io.h>
using namespace std;
int main()
{
fstream file;
char filename[100];
FILE *fp;
strcpy(filename, "test.txt");
file.open(filename, ios::in);
if (!file)
{
cout << filename << " not exist" << endl;
}
else
{
cout << filename << " exist" << endl;
}
file.close();
fp = fopen(filename, "r");
if (fp == NULL)
{
cout << filename << " not exist" << endl;
}
else
{
cout << filename << " exist" << endl;
}
fclose(fp);
if (_access(filename, 0) != -1)
{
cout << filename << " exist" << endl;
}
else
{
cout << filename << " not exist" << endl;
}
return 0;
}
某大牛的总结:
http://blog.csdn.net/roger_77/article/details/1538447