C++でファイルが存在するか否かを判断する方法
一番進んで書いたシステムでは結果データを保存する必要がありますが、結果データを保存する場合、そのデータが既に存在していれば保存できないので、まずそのデータが存在するかどうかを判断する必要があります.判断方法は以下の通りです.
コンパイル:g+-o fileexists fileexisttest.cpp
実行:./fileexists
OK、運転可能
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
char *savePath = "/home/zhuwei/contour/linearIteration.shp";
fstream f2;
f2.open(savePath);
if(!f2)
{
cout<<" "<<endl;
f2.close();
}
else
{
cout<<" "<<endl;
f2.close();
}
return 0;
}
コンパイル:g+-o fileexists fileexisttest.cpp
実行:./fileexists
OK、運転可能