You are on page 1of 1

1 #include <iostream>

2 #include <fstream>
3 using namespace std;
4
5 struct alumno
6 {
7 char nombre [100];
8 char apellido [100];
9 int codigo;
10 };
11
12 void RegistroAlum (alumno &alu)
13 {
14 cout << " Ingrese nombre del alumno: ";
15 gets (alu.nombre);
16 cout << " Ingrese apellidos del alumno: ";
17 gets (alu.apellido);
18 cout << " Ingrese codigo del alumno: ";
19 cin >> alu.codigo;
20 }
21
22 int main (){
23 fstream alum;
24 alumno alu;
25 int bytsAlum;
26 alum.open ( "alumno.bin" , ios::out| ios::binary );
27 if (alum.fail())
28 cout << " ERROR DE APERTURA..." << endl;
29 else
30 {
31 RegistroAlum(alu);
32 bytsAlum = sizeof (alu);
33 alum.write ((char*) &alu, bytsAlum);
34 }
35 alum.close();
36 alum.open ( "alumno.bin" , ios::in | ios::binary );
37 if (alum.fail())
38 cout << " ERROR DE APERTURA..." << endl;
39 else
40 {
41 while ( alum.peek() != EOF)
42 {
43 bytsAlum = sizeof (alu);
44 alum.read ((char*) &alu, bytsAlum);
45 cout << " NOMBRE COMPLETO " << alu.nombre << " " << alu.apellido << endl;
46 }
47 }
48 alum.close();
49 return 0;
50 }

You might also like