Stworzyłem klase String (uproszczony odpowiednik klasy string ) oraz prostą klase Dog:
#include<iostream>
#include<String.h>
#include<fstream.h>
class Dog
{
private:
int age; String name; char* city
public:
friend ostream& operator<<(ostream& ost, const Dog& dog)
{
ost<<dog.GetName()<<"\t"<<dog.GetCity()<<"\tWiek :"<<dog.GetAge()<<endl;
return ost;
}
......
};
metodami :
Dog dog;
ifstream fin("c:\\test_dog.doc",ios::binary );
if(!fin){cout<<"\nUnsuccessful trial ..."<<endl;}
fin.read((char*)&dog, sizeof dog);
cout<<dog<<endl;
fin.close();
zczytuje zawartość.
Dlaczego nie mogę odczytać z pliku binarnego zmiennej city typu String?
Odczyt zmiennej name typu char jest OK.