깐우의 세상 만들기

(C++) 해당 파일 존재시 다음 번호의 파일 생성하기(파일입출력) 본문

Book / Study

(C++) 해당 파일 존재시 다음 번호의 파일 생성하기(파일입출력)

깐우 2011. 7. 26. 19:14
파일 출력할때의 한 방법

tst_0.txt라는 파일이 이미 있으면 그다음에는 tst_1.txt라는 파일을 생성하는 방법

귀찮으니 설명은 소스로 대체

void AnalyzePSNR::RetrieveProcessedFiles()
{
ifstream fin;
ofstream fout;
char filename[255];
bool OpenFileSuccess=false;
int i=0;
while(OpenFileSuccess==false)
{
sprintf_s(filename,"Final_Total_Normal_PSNR_%d.txt",i);
fin.open(filename);

if(!(fin.is_open()))
{
OpenFileSuccess = true;
}
else
{
i++;
}
fin.close();
}
fout.open(filename);

fout<<"Normal_PSNR"<<"\t"<<"\t"<<"Average_Normal_PSNR: "<<Average_Normal_PSNR<<endl;
for(int i=0;i<this->number_of_frames_in_Processed_GOP;i++)
{
fout<<Normal_Pocessed_PSNR[i]<<endl;
}
fout.close();
}