Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- class Student{
- protected:
- string imie;
- string nazwisko;
- public:
- Student();
- Student(string,string);
- string getImie(){
- return this->imie;
- }
- string getNazwisko(){
- return this->nazwisko;
- }
- void zapisz(string src){
- fstream file;
- file.open(src.c_str(),ios::out); // .c_str() zwraca łańcuch tylko do odczytu
- file<<this->imie<<endl;
- file<<this->nazwisko<<endl;
- file.close();
- }
- void wczytaj(string src){
- fstream file;
- file.open(src.c_str(),ios::in);
- getline(file,this->imie);
- getline(file,this->nazwisko);
- file.close();
- }
- };
- Student::Student(){
- nazwisko="";
- imie="";
- }
- Student::Student(string imie,string nazwisko){
- this->nazwisko=nazwisko;
- this->imie=imie;
- }
- int main()
- {
- string plik = "plik.txt";
- Student s1("Imie","Nazwisko");
- s1.zapisz(plik);
- Student s2();
- s2.wczytaj(plik);
- cout<< s2.getImie() << endl << s2.getNazwisko();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement