filestream not working here

i have this code and everything works except for my void remove function here is the code:
can someone help me find where i go wrong? thanks

#include<iostream>
#include<iomanip>
#include<string>
#include<windows.h>
#include<fstream>
#include<stdio.h>
using namespace std;


void reg();
void ClearScreen();
void exit();
void prompt();
void stat();
void menu();
void view();
void about();
void remove();

struct Details
{
char fName[200];
char mi[200];
char lName[200];
char addr[350];
int age;
char date[250];


} use;


void main()
{

ifstream readFile;
ofstream genFile;
readFile.open("data.txt");
if(readFile.fail())
{
cout<<"Required File data.txt does not exist"<<endl<<"No existing records was found. Program will now generate file automatically"<<endl<<"Press ENTER key to proceed to main menu"<<endl;
readFile.close();
genFile.open("data.txt");
}
else if(readFile.good())
{
cout<<"File data.txt exists. Press ENTER key to proceed to the main menu"<<endl;
}
readFile.close();
genFile.close();
menu();

}

void menu()
{
cin.ignore();
int choice;


ClearScreen();
cout<<"*****************Voter's Registration*****************"<<endl;
cout<<"1. Registration"<<endl;
cout<<"2. Search"<<endl;
cout<<"3. Delete"<<endl;
cout<<"4. Status"<<endl;
cout<<"5. About"<<endl;
cout<<"6. View"<<endl;
cout<<"7. Exit"<<endl;
cout<<"******************************************************"<<endl<<endl;
cout<<"Choice: ";
cin>>choice;

if(choice==1)
{
reg();
}
else if (choice==3)
{
remove();
}
else if(choice==4)
{
stat();
}
else if(choice==5)
{
about();
}
else if(choice==6)
{
view();
}
else if(choice==7)
{
exit();
}

}


void about()
{
ClearScreen();
cout<<"About the Program"<<endl<<endl;
cout<<"Voter's Registration Program"<<endl;
cout<<"This program allows its user to facilitate a computer orriented Voter's Registration."<<endl;
cout<<"It implements the usage of Structures and heavily relies on File Streams to"<<endl<<" save, access, delete and search data";

cout<<"\n\nCopyright John Christian Lorenzo";
}

void reg()
{
char data[250];
ofstream genTemp;
genTemp.open("temp.txt");
genTemp.close();
fstream fin;
fin.open("temp.txt",ios::out|ios::in);
ClearScreen();
if(fin.good())
{
cin.ignore();
cout<<"Please fill out the following important"<<endl<<"fields to accomplish your Voter's Registration"<<endl<<endl;
cout<<"First Name: ";
cin.getline(use.fName,200);
fin<<use.fName<<" ";
cout<<"Middle Name: ";
cin.getline(use.mi,200);
fin<<use.mi<<" ";
cout<<"Last Name: ";
cin.getline(use.lName,200);
fin<<use.lName<<"\n";
cin.ignore();
cout<<"Address: ";
cin.getline(use.addr,350);
fin<<use.addr<<"\n";
cout<<"Age: ";
cin>>use.age;
fin<<use.age<<"\n";
cin.ignore();
cout<<"Birth Date(MM/DD/YYYY): ";
cin.getline(use.date,200);
fin<<use.date<<"\n";
fin.close();
if(use.age>=18)
{
cin.ignore();
ifstream readFile("temp.txt");
ofstream writeFile("data.txt",ios::app);
while(!readFile.eof())
{
readFile.getline(data,250);


}

// cout<<data;
writeFile<<data;
writeFile.close();
readFile.close();
cout<<"\n\nVoter was successfully registered!!";
menu();
}
else if(use.age<18)
{
cin.ignore();
cout<<"Person being resitered is not qualified for registration!!"<<endl<<"Minimum Age not met";
menu();

}




}
}

void stat()
{
int ctr=0;
char detail[2000];
ClearScreen();
cout<<"\t\tProgram Status"<<endl<<endl;
ifstream readStat("data.txt");
while(!readStat.eof())
{
readStat.getline(detail,2000);
}

readStat.close();


for(int i=0; i<strlen(detail); i++)
{
if(detail[i]=='*')
{
ctr=ctr+1;
}

}
cout<<"Voters Registered: "<<ctr<<endl;

}



void view()
{

char display[6000];
ClearScreen();
cout<<"NAME"<<"\t\t\t\t\t\tADDRESS"<<"\tCONTROL NUMBER"<<endl<<endl<<endl;
ifstream readFile;
readFile.open("data.txt");
while(!readFile.eof())
{
readFile.getline(display,4000);
}

int i=0;
int j=0;

while(display[i]!='|')
{
cout<<display[i];
i++;
}
cout<<endl;

}

void remove()
{
ofstream genFile("data.txt");
char name[20],ch;
cout<<"Enter the name of the person whose record you wanna delete : "<<endl;
cin>>name;

ofstream outfile;
//creates a temporary file of stream outfile
outfile.open("delete.TXT",ios::out);

genFile.seekg(0L,ios::beg);
//position get pointer at the beginning of the file

while(genFile.read((char*)&use,sizeof(use)))
{
if(strcmp(use.lName,name)==0)
{
cout<<endl<<use.lName;

cout<<endl<<"Confirm the record Deletion?(Y/N)";
cin>>ch;
}

if(ch=='Y'||ch=='y')
{
genFile.seekg(0L,ios::beg);
while(genFile.read((char*)&use,sizeof(use)))
{
if(strcmp(use.lName,name)!=0)
outfile.write((char*)&use,sizeof(use));
}
cout<<endl<<"Record Deleted"<<endl;
outfile.close();
genFile.close();

remove("data.txt");
rename("temp.txt","data.txt");

genFile.open("data.txt",ios::binary|ios::in|ios::out);

}


}

if (ch=='N'||ch=='n')
{
cout<<endl<<"Deletion Cancelled"<<endl;

outfile.close();

return ;
}
}


void ClearScreen()
{
HANDLE hStdOut;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD count;
DWORD cellCount;
COORD homeCoords = { 0, 0 };
hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
if (hStdOut == INVALID_HANDLE_VALUE) return;
if (!GetConsoleScreenBufferInfo( hStdOut, &csbi ))
return;
cellCount = csbi.dwSize.X *csbi.dwSize.Y;
if (!FillConsoleOutputCharacter(
hStdOut,
(TCHAR) ' ',
cellCount,
homeCoords,
&count
)) return;
if (!FillConsoleOutputAttribute(
hStdOut,
csbi.wAttributes,
cellCount,
homeCoords,
&count
)) return;
SetConsoleCursorPosition( hStdOut, homeCoords );
}

void exit()
{
exit(0);
}
Any chance of formatting your code? There's quite a lot of it and it's unreadable as presented. You have formatted your code in previous posts.
Topic archived. No new replies allowed.