delete record function

Hey Guys,

I need some help for my delete function. would you please have a look at my code and give me suggestions...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
void del_rec()
{
    string Target;
	int Found=0;
		system("cls");

	ofstream rectemp ("rectemp.txt");
	ifstream Records ("Records.txt");
	if ( !Records )
	{
		cout << "\nCouldn't Open the File! File Does Not Exist!\n\n";
		system("pause");
		main_function();
	}
	else if ( Records.peek() == std::ifstream::traits_type::eof() )
	{
		cout << "\nNo Student Records In File Yet! FILE IS EMPTY!!!\n\n";
		system("pause");
		main_function();
	}
	
	else{
		cout << "\n\n";
		cout << "\t--------------- DELETE ----------------";
		cout << "\n\n";
		cout << "\tEnter a Student LastName to Delete His/Her Record: ";
		cin >> Target;
		while(!Records.eof())
			{
			Records >> stureg.fname >> stureg.lname >> stureg.stdid >> stureg.shsh >> stureg.gen >> stureg.phone >> stureg.emailadd;
			if(Records.eof())
				break;
			if (Target.compare(stureg.lname) !=0)
			{
				rectemp << stureg.fname <<setw(25)<< stureg.lname <<setw(35)<< stureg.stdid <<setw(25)<< stureg.shsh <<setw(15)<< stureg.gen <<setw(6)<< stureg.phone <<setw(15)<< stureg.emailadd <<setw(25)<< endl;
			}
			else {
				Found=1;
				cout << ".......Student Record Found!\n";
				system("pause");
			    system("cls");
				cout << "1 Record Found : \n\n\n";
				cout << "First Name: " << stureg.fname << endl;
				cout << "Last Name: " << stureg.lname << endl;
				cout << "Student ID: " << stureg.stdid << endl;
				cout << "Student Card ID: " << stureg.shsh << endl;
				cout << "Student Phone No.: " << stureg.phone << endl;
				cout << "E-mail: " << stureg.emailadd << endl;
				cout << "Student Gender: " << stureg.gen << endl;
				system("pause");
				}
			}
			if (!Found)
			{
			cout << "\tRECORD NOT FOUND\n";//incase no files are located
			}
		printf("\tRECORD DELETED!!\n");
		system ("pause");

		Records.close();
		rectemp.close();
		remove("Records.txt");
		rename("rectemp.txt","Records.txt");
	main_function();	}

	}
btw:

 
while(!Records.eof())


with this:

1
2
if(Records.eof())
	break;


what's the difference?
Thanks! I removed it and changed the file definitions to

1
2
3
4
	ofstream rectemp ("rectemp.txt");
	//ifstream Records ("Records.txt");
	fstream Records;
			Records.open("Records.txt", ios::in | ios::out);
Topic archived. No new replies allowed.