Daehyun
4/23/2016 - 3:36 PM

isFileExist.cpp

#include <fstream>
#include <iostream> 
#include <string> 

bool isFileExist(const char *fileName)
{
	std::ifstream file(fileName); 
	return file.good(); 
}

int main(int argc, char const *argv[])
{
	std::string rootFilename;
	for(int i=0; i<10000; i++) {
		char ch[5]; 
		sprintf(ch, "%04d", i);
		rootFilename = "resortLess"; 
		rootFilename += ch; 
		rootFilename += ".root"; 
		if(isFileExist(rootFilename.c_str())) {
			continue; 
		}
		break; 
	}
	std::cout << rootFilename << std::endl; 
	return 0;
}