|
nyil_operatorC++.cpp
| |
1 // PÉLDAPROGRAM POINTER HASZNÁLATÁRA NYÍL OPERÁTORRAL, STRUKTÚRÁVAL
2 #include <iostream>
3 #include <fstream>
4
5 #define N 10
6
7 using namespace std;
8
9 struct diak {
10 char vnev[30];
11 char knev[30];
12 int kor;
13 float t_atlag;
14 char osztaly[4];
15 };
16
17 struct diak tanulo; // "normál" adatkezelés: tanulo egy diak struktúra típusú adat
18 struct diak* t=NULL; // "pointeres" adatkezelés: t egy diak struktúrára mutató változó (kezdőértéke a "sehova sem mutat"
19
20 int main()
21 {
22 setlocale(LC_ALL,"");
23 ifstream fbe("diakok.txt");
24 t = (diak*) malloc(sizeof(diak)*N);
25 cout << "Normál adatként:" << endl;
26 while(fbe>>tanulo.vnev and fbe>>tanulo.knev and fbe>>tanulo.kor and fbe>>tanulo.t_atlag and fbe>>tanulo.osztaly)
27 {
28 cout << tanulo.vnev << " " << tanulo.knev << " " << tanulo.kor << " " << tanulo.t_atlag << " " << tanulo.osztaly << endl;
29 }
30 fbe.close();
31 cout << endl;
32 fbe.open("diakok.txt");
33 cout << "Pointerként:" << endl;
34 while(fbe>>t->vnev and fbe>>t->knev and fbe>>t->kor and fbe>>t->t_atlag and fbe>>t->osztaly)
35 {
36 cout << t->vnev << " " << t->knev << " " << t->kor << " " << t->t_atlag << " " << t->osztaly << endl;
37 }
38
39 return 0;
40 }
41