Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- using namespace std;
- // struktura - składnia:
- struct Student // Student od tego momentu jest nazwą naszego własnego typu zmiennej
- {
- string imie;
- string nazwisko;
- int wiek;
- string e_mail;
- double srednia_ocen;
- };
- ostream& operator<<(ostream& out, const Student& student)
- {
- out << student.imie << ' ' << student.nazwisko << " (adres e-mail: " << student.e_mail << "), wiek " << student.wiek << " lat, srednia ocen: " << student.srednia_ocen;
- return out;
- }
- istream& operator>>(istream& in, Student& student)
- {
- in >> student.imie >> student.nazwisko >> student.wiek >> student.e_mail >> student.srednia_ocen;
- return in;
- }
- bool plik_danych(Student t[5])
- {
- ifstream plik_in;
- plik_in.open("dane_studentow.txt");
- if (plik_in.fail())
- return 1; // zwrócenie błędu
- for (int i = 0; i < 5; i++)
- {
- plik_in >> t[i];
- }
- plik_in.close();
- return 0; // zwrócenie braku błędu
- }
- int main()
- {
- Student t[5];
- if (plik_danych(t))
- {
- cout << "Nie udalo sie odczytac danych z pliku. Nastapi zamkniecie programu.\n";
- return 0;
- }
- for (int i = 0; i < 5; i++)
- {
- cout << t[i] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement