How to find a files from a folder then clear data from that file?

In another function definition, I had created a function that creates files so I want to know how to find a file in a folder because it has many files. I want to find a specific file then removes data from that file.

This is my code, you can see at Case 1.

void del_data(){
system("cls");
char again;
int x;
fstream delete1;
fstream delete2;
fstream delete3;
string input;
string room;
do
{
cout<<"Please select room type."<<endl;
cout<<endl;
cout<<"1. Single Rooms "<<endl;
cout<<"2. Family Rooms "<<endl;
cout<<"3. Royal Rooms "<<endl;
cout<<endl;
cout<<"\nRooms type: ";
cin>>x;
cout<<endl;
system("cls");
switch(x)
{
case 1:
{
cout<<"Room No: "<<endl;
cin>>room;
delete1.open(room.c_str(), ios::trunc);
/*if(delete1 == NULL)
{
cout<<"File is already empty."<<endl;
Sleep(1500);
return del_data();
}

else
{*/
/* delete1.open(room.c_str(), ios::out | ios::trunc);
cout<<"Data has been deleted."<<endl;
cout<<endl;*/

delete1.close();
break;
}
case 2:
delete2.open("rooms2.txt", ios::out | ios::trunc);
if(delete2 == NULL)
{
cout<<"File is already empty."<<endl;
return del_data();
}
else
{
cout<<"Data has been deleted."<<endl;
cout<<endl;
}
delete2.close();
break;
case 3:
delete3.open("rooms3.txt", ios::out | ios::trunc);
if(delete3 == NULL)
{
cout<<"File is already empty."<<endl;
return del_data();
}
else
{
cout<<"Data has been deleted."<<endl;
cout<<endl;
}
delete3.close();
break;
default:
cout<<"Input is invalid!"<<endl;
Sleep(2000);
return del_data();
}

cout<<"Enter Y to run this function again or N to cancel: ";
cin>>again;
cout<<endl;
cout<<"_____________________________________________"<<endl;
}
while (again=='Y' || again=='y');
Topic archived. No new replies allowed.