any idea about delete ?

#include <iostream>
#include <conio.h>
#include <fstream>
#include <iomanip>
#include <stdlib.h>
int main()
{
char name[30];
double IC;
const int SIZE = 40 ;
char address[60],hpnum[SIZE],opnum[SIZE],mpnum[SIZE];
int choice;
double requestIC;



do
{
clrscr();
cout << "\n\n\n -------------------<1> Save Information------------------ " << endl;
cout << " -------------------<2> Retrieve Information-------------- " << endl;
cout << " -------------------<3> Delete information----------------" <<endl;
cout << " -------------------<4> Exit -----------------------------"<< endl;
cout << " \n \nPlease selecr your choice: " << endl;
cin >> choice;


if (choice == 1)
{//open if 1
clrscr();
cout << "Please enter your friend's name : ";
cin.ignore();
cin.getline(name,30);
cout << endl;
cout << "Please enter friend's IC number : ";
cin >> IC;
cout << endl;
cout << "Please enter your friend's address : ";
cin.ignore();
cin.getline(address,60);
cout << endl;
cout << "Please enter your friend's home phone number : ";
cin >> hpnum;
cout << endl;
cout << "Please enter your friend's office phone number : ";
cin >>opnum;
cout << endl;
cout << "Please enter your friend's mobile phone number : ";
cin >> mpnum;

ofstream outfile;
outfile.open("info.txt",ios::app);

outfile << name << endl;
outfile << setprecision(12)<<IC << endl;
outfile << address << endl;
outfile << hpnum << endl;
outfile << opnum << endl;
outfile <<mpnum << endl;


outfile.close();
cout << "Please press any key to continues... " << endl;
getch();



}//close if 1


if (choice == 2)
{ //open if 2
clrscr();
cout << "Please Input IC : ";
cin >> requestIC;

clrscr();

ifstream infile;
infile.open("info.txt");


while(!infile.eof() && infile != '\0')
{ //open while

infile.getline(name,30);
infile >> IC;
infile.ignore();
infile.getline(address,60);

infile >> hpnum;
infile >> opnum;
infile >> mpnum;
infile.ignore();


if(IC == requestIC)
{ //open if while 1
cout << "Name : ";
cout << name << endl;
cout << "IC : ";
cout << setprecision(12)<<IC << endl;
cout << "Address : ";
cout <<setprecision(40)<< address << endl;
cout << "Home Phone Number : ";
cout << hpnum << endl;
cout << "Office Phone Number : ";
cout << opnum << endl;
cout << "Mobile Phone Number : ";
cout << mpnum << endl;

break; //terminate loop if ic is matching with request
} //close if while 1

if(infile.eof() && IC != requestIC)
{//open if while 2
cout << "No such IC " << endl;
} //close if while 2
} //close while

infile.close();
cout << "Please press enter to continues... " << endl;
getch();

} //close if 2
}while (choice!=4);

if (choice == 4)
{
exit(1);
}


getch();
return 0;
}


This is an application could display a person's information from a text file ,when you key in the identification card number.I had done the part of of record the information and retrieve the information,but wonder how to do the part of the delete information .How to write the "delete" function actually ?I had refer some of the tutorial ,they mentioned something about like"->" or even call WINDOWS system delete function to get rid of the data in the text file.
To write delete function follow this algo-
open file
ask user to which record he wants to remove
make an output file
make a loop that will go from first record to last.
write all the records in the output file except the record which user has entered
delete your data file
rename output file as your data file name.
No, i mean how to type the lines of code ,because i never use the delete function before ,i don't even know how is the delete fucntion suppose to be
Just use the delete keyword with the variable to be deleted on the right of it.

Ex
delete name;
if (choice == 3)
{
clrscr();
ifstream infile ;
infile.open("info.txt");

cout <<"Which profile you want to delete ?"<<endl;
cout <<"Please enter the IC number to indicate the profile :";
cin >> requestIC ;

ofstream outfile ;
outfile.open("updateinfo.txt");

while(!infile.eof() && infile != '\0')
{
infile.getline(name,30);
infile >> IC;
infile.ignore();
infile.getline(address,60);

infile >> hpnum;
infile >> opnum;
infile >> mpnum;
infile.ignore();

if(IC != requestIC)
{
outfile << name << endl;
outfile << setprecision(12)<<IC << endl;
outfile << address << endl;
outfile << hpnum << endl;
outfile << opnum << endl;
outfile <<mpnum << endl;

}
}
infile.close();
outfile.close();
cout << "Please press enter to continues... " << endl;
getch();
}

This is a part of the lines of code as the delete fucntion according to the algorithm of aakashjohari.It still incomplete because of the final two lines of algorithm i don't know how to write.....

delete your data file
rename output file as your data file name.


anybody could show me how to write it ?
#include <iostream>
#include <conio.h>
#include <fstream>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>

void remove();

int main()
{
char name[30];
double IC;
const int SIZE = 40 ;
char address[60],hpnum[SIZE],opnum[SIZE],mpnum[SIZE];
int choice;
double requestIC;



do
{
clrscr();
cout << "\n\n\n -------------------<1> Save Information------------------ " << endl;
cout << " -------------------<2> Retrieve Information-------------- " << endl;
cout << " -------------------<3> Delete information----------------" <<endl;
cout << " -------------------<4> Exit -----------------------------"<< endl;
cout << " \n \nPlease selecr your choice: " << endl;
cin >> choice;


if (choice == 1)
{//open if 1
clrscr();
cout << "Please enter your friend's name : ";
cin.ignore();
cin.getline(name,30);
cout << endl;
cout << "Please enter friend's IC number : ";
cin >> IC;
cout << endl;
cout << "Please enter your friend's address : ";
cin.ignore();
cin.getline(address,60);
cout << endl;
cout << "Please enter your friend's home phone number : ";
cin >> hpnum;
cout << endl;
cout << "Please enter your friend's office phone number : ";
cin >>opnum;
cout << endl;
cout << "Please enter your friend's mobile phone number : ";
cin >> mpnum;

ofstream outfile;
outfile.open("info.txt",ios::app);

outfile << name << endl;
outfile << setprecision(12)<<IC << endl;
outfile << address << endl;
outfile << hpnum << endl;
outfile << opnum << endl;
outfile <<mpnum << endl;


outfile.close();
cout << "Please press any key to continues... " << endl;
getch();



}//close if 1


if (choice == 2)
{ //open if 2
clrscr();
cout << "Please Input IC : ";
cin >> requestIC;

clrscr();

ifstream infile;
infile.open("info.txt");


while(!infile.eof() && infile != '\0')
{ //open while

infile.getline(name,30);
infile >> IC;
infile.ignore();
infile.getline(address,60);

infile >> hpnum;
infile >> opnum;
infile >> mpnum;
infile.ignore();


if(IC == requestIC)
{ //open if while 1
cout << "Name : ";
cout << name << endl;
cout << "IC : ";
cout << setprecision(12)<<IC << endl;
cout << "Address : ";
cout <<setprecision(40)<< address << endl;
cout << "Home Phone Number : ";
cout << hpnum << endl;
cout << "Office Phone Number : ";
cout << opnum << endl;
cout << "Mobile Phone Number : ";
cout << mpnum << endl;

break; //terminate loop if ic is matching with request
} //close if while 1

if(infile.eof() && IC != requestIC)
{//open if while 2
cout << "No such IC " << endl;
} //close if while 2
} //close while

infile.close();
cout << "Please press enter to continues... " << endl;
getch();

} //close if 2

if (choice == 3)
{
remove();
}



}while (choice!=4);

if (choice == 4)
{
exit(1);
}


getch();
return 0;
}

void remove(int result,char name[30], double IC,const int SIZE = 40, char address[60],hpnum[SIZE],opnum[SIZE],mpnum[SIZE], double requestIC)
{
clrscr();
ifstream infile ;
infile.open("info.txt");

cout <<"Which profile you want to delete ?"<<endl;
cout <<"Please enter the IC number to indicate the profile :";
cin >> requestIC ;

ofstream outfile ;
outfile.open("updateinfo.txt");

while(!infile.eof() && infile != '\0')
{
infile.getline(name,30);
infile >> IC;
infile.ignore();
infile.getline(address,60);

infile >> hpnum;
infile >> opnum;
infile >> mpnum;
infile.ignore();

if(IC != requestIC)
{
outfile << name << endl;
outfile << setprecision(12)<<IC << endl;
outfile << address << endl;
outfile << hpnum << endl;
outfile << opnum << endl;
outfile <<mpnum << endl;

}
}
infile.close();
outfile.close();

if( remove( "info.txt" ) != 0 )
{
perror( "Error deleting entries" );
}
else
{puts( "Entries successfully deleted" );
}

char oldname[] = "updateinfo.txt";
char newname[] = "info.txt";
result= rename( oldname , newname );
if ( result == 0 ){
puts ( ".......Done!" );}
else
{perror( "Error " );}

cout << "Please press enter to continues... " << endl;
getch();
}



Finally , i had successfuly write the last two part of the algorithm.What i want is to make a function for the remove() in case i want to use it later for further coding.But the error of type name expected occured.How to solve it ?By the way i'm using the Borland C++ compiler,is there any problems messing with it ?
Topic archived. No new replies allowed.