处理文件 / 基本操作

#include <sys/stat.h>
#include <fstream>
using namespace std;

char* fileName = "file.txt";

//first method
ifstream infile(fileName);
bool exists1 = infile.good();

//second method
struct stat buffer;
bool exists2 = stat(fileName, &buffer) == 0;