473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Why does it show the last data 2 times ?

#include <iostream>
using namespace std;

#include <fstream>

struct student
{
char name[40];
int id;
};

int main ()
{
int menu;
student std;
do
{
cout << "\n ========================================" << endl;
cout << " Welcome To Student Record Program " << endl;
cout << " ========================================" << endl;
cout << "\n 1. Show A Student Info " << endl;
cout << " 2. Insert A New Student Record " << endl;
cout << " 3. Exit Program " << endl;
cout << "\n Enter Your Choice : ";
cin >> menu;
cin.ignore(80,'\n');

if (menu <1 || menu >3) cout << "\n Please Enter The Correct Choice" <<endl;

else if (menu == 1)
{
ifstream stdfile("student", ios::in | ios::binary);
if (stdfile.is_open())
{
cout << "\n\n ========================================"<<endl;
cout << " The Student Record "<< endl;
cout << " ========================================\n"<<endl;
while (!stdfile.eof())
{
stdfile.read((char*)(&std), sizeof(student));
cout << " " << std.id << "\t" << std.name << endl;
}
stdfile.close();
}
else
{
cout << "\n\n ========================================"<<endl;
cout << " No Data Record "<< endl;
cout << " ========================================\n"<<endl;
}
system("PAUSE");
}

else if (menu == 2)
{ cout << "\n\n ========================================"<<endl;
cout << " Enter A New Student Record "<< endl;
cout << " ========================================\n"<<endl;
cout << " Enter Student ID number: ";
(cin >> std.id).get();
cout << " Enter Student Name: ";
cin.getline(std.name,40);
ofstream rstdfile("student", ios::out | ios::app | ios::binary);
rstdfile.write((char*)(&std), sizeof(student));
rstdfile.close();
}
} while (menu != 3);
system("PAUSE");
return 0;
}




========================================
The Student Record
========================================

123 abc
456 def
789 ghi
789 ghi
Press any key to continue . . .
Jun 19 '06 #1
0 1273

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
4
by: Craig831 | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
21
by: thomson | last post by:
Hi folks, Does any one have any idea which platform does GMAIL works, whether its JSP, ASPX or any other Regards thomson
2
by: Doru Roman | last post by:
Hi, I use C# to validate an XML document. It issues error messages and I do not understand why. Here is the XML document: <bookstore xmlns="http://tempuri.org/books.xsd"> <book...
14
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it...
25
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does parseInt('09') give an error? ----------------------------------------------------------------------- ...
89
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
19
by: active | last post by:
The ColorPalette class has no constructor so how does one use it? I define a variable by: Dim cp as ColorPalette but don't know how assign an object to the variable. Thanks in advance
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.