i made a function that first reads the file and checks if it exists or not and then it removes it after a confirmation but if i do directly like
remove("a.text");
it deletes the file that has the name a.txt but when i use my function
int deletediary()
{
string searchfilename;
cout<<"\nPlease enter the filename to be searched\n";
cin>>searchfilename;
searchfilename.append(".txt");
fileread.open(searchfilename.c_str());
if(!fileread){
cout<<"\nERROR :Either you didn't enter an invalid date or you entered an date with no entry\n\n";
A :
cout<<"Continue to search? (y/n)\n";
if(getch()=='y')
{
modifydiary();
}
else if(getch()=='n')
{
menuview();
}
else
{
cout<<"Enter Correct Option\n";
goto A;
}
}
else{
system("cls");
int i;
B :
cout<<"Are you sure you want to remove this diary entry? (y/n)";
if(getch()=='y')
{
remove(searchfilename.c_str());
}
else if(getch()=='n')
{
menuview();
}
else
{
cout<<"Enter Correct Option\n";
goto B;
}
cout<<"INFO :Deleted!!!";
system("pause");
menuview();
}
it only checks the filename but does not delete it.