#ifndef KONTAKT_H
#define KONTAKT_H
#include <string>
using namespace std;
class Kontakt
{
public:
string PodajImie() { return Imie; }
string PodajNazwisko() { return Nazwisko; }
void ZapiszImie(string imie) {Imie = imie; }
void ZapiszNazwisko(string nazwisko) { Nazwisko = nazwisko; }
private:
string Imie;
string Nazwisko;
};
#endif
#include <vcl.h>
#include <iostream>
#include <fstream>
#include "kontakt.h"
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
using namespace std;
void zapisz()
{
ofstream ofs("lol.txt", ios::binary);
Kontakt *osoba = new Kontakt;
osoba->ZapiszImie("imie");
osoba->ZapiszNazwisko("nazwisko");
ofs.write((char*)(osoba), sizeof(Kontakt));
ofs.close();
delete osoba;
}
void wczytaj()
{
ifstream ifs("lol.txt", ios::binary);
char* temp = new char[sizeof(Kontakt)];
ifs.read(temp, sizeof(Kontakt));
Kontakt* osoba = (Kontakt*)(temp);
cout << osoba->PodajImie() << " " << osoba->PodajNazwisko() << endl;
delete [] temp;
ifs.close();
}
int main(int argc, char* argv[])
{
zapisz();//<----problem się pojawia jak usunę ta linijka
wczytaj();
system("PAUSE");
return 0;
}