anketa ar;
int size = 0;
int k = 0;
fstream fout ("test.dat", ios::binary | ios::app);
if(!fout)
{
cout<<"ERROR!!!!!123";
return 1;
}
cout<<"Vvedite kol-vo struct"<<endl;
cin >> k;
for(int i = 0; i<k; i++){
cout<< i+1 <<" Struct : " << endl;
cout << "Year\n";
cin >> ar.year;
cin.ignore();
cout << endl << "FIO \n";
getline(cin, ar.fio, '\n');
cin.clear();
size = sizeof(ar.year) + ar.fio.length() + 1;
fout.write((char*)&ar,sizeof(size));
size = 0;
}
fout.close();
fstream file("test.dat", ios::binary | ios::in);
if(!file)
{
cout<<"ERROR!!!!!11";
return 404;
}
if (getline( file, ar.fio, '\0' ))
do
{
cout << endl << " Struct String: " << ar.fio << " Year " << ar.year << endl;
}
while(getline( file, ar.fio, '\n' ));
file.close();