I'm trying to read my class in binary format like this:
FILE* file = fopen(filePath.toStdString().c_str(), "rb");
if (file == NULL)
{
QMessageBox::critical(this, "Ошибка!", "Ошибка при открытии файла!");
return;
}
while (!feof(file))
{
Dog* dog;
fread(dog, sizeof(Dog), 1, file);
_list->emplace_back(dog);
}
fclose(file);
But I get an error: the program crashes. The file exists and the data is written like this:
FILE* file = fopen(filePath.toStdString().c_str(), "wb");
if (file == NULL)
{
QMessageBox::critical(this, "Ошибка!", "Ошибка при открытии файла!");
return;
}
for (int i = 0; i < _list->size(); i++)
{
fwrite(_list->get(i), sizeof(Dog), 1, file);
}
fclose(file);
This code runs without errors. Help please :(