У меня такое решение получилось
Использовал winapi
class LoaderNetw : public DataCl
{
public:
LoaderNetw(Data *);
~LoaderNetw();
int openNetw();
void write();
void read();
private:
void *file;
unsigned char type = 0;
unsigned char ch;
};
int neural_network_lib::LoaderNetw::openNetw()
{
std::exception e = std::exception("File it's open", 0);
try
{
this->file = ::CreateFile(TEXT(url),
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (GetLastError() == ERROR_NOT_SUPPORTED)
throw std::exception::exception("File not open", 1);
}
catch (const std::exception&e)
{
return 1;
}
return 0;
}
void neural_network_lib::LoaderNetw::write() {
::SetFilePointer(this->file, 0, 0, FILE_BEGIN);
DWORD fl = 0;
::WriteFile(this->file,
&this->type, sizeof this->type, &fl, NULL);
::SetFilePointer(this->file, fl, 0, FILE_CURRENT);
::WriteFile(this->file,
&this->d->iQuantLayer,
sizeof this->d->iQuantLayer,
&fl,
NULL);
for (int i = 0; i < this->d->iQuantLayer; i++) {
::SetFilePointer(this->file, fl, 0, FILE_CURRENT);
::WriteFile(this->file,
&this->d->piQuantNInLayer[i],
sizeof i,
&fl,
NULL);
}
for (int i = 1; i < this->d->iQuantLayer; i++)
for (int j = 0; j < this->d->piQuantNInLayer[i]; j++)
for (int k = 0; k < this->d->piQuantNInLayer[i - 1]; k++) {
::SetFilePointer(this->file, fl, 0, FILE_CURRENT);
::WriteFile(this->file,
&this->d->pppdWeights[i][j][k],
sizeof this->d->pppdWeights[i][j][k],
&fl,
NULL);
}
}
void neural_network_lib::LoaderNetw::read() {
DWORD fl = 0;
::SetFilePointer(this->file, 0, 0, FILE_BEGIN);
::ReadFile(this->file, &this->ch, sizeof this->ch, &fl, NULL);
::SetFilePointer(this->file, fl, 0, FILE_CURRENT);
::ReadFile(this->file,
&this->d->iQuantLayer,
sizeof this->d->iQuantLayer,
&fl,
NULL);
for (int i = 0; i < this->d->iQuantLayer; i++) {
::SetFilePointer(this->file, fl, 0, FILE_CURRENT);
::ReadFile(this->file, &this->d->piQuantNInLayer[i], sizeof double(1), &fl, NULL);
}
for (int i = 1; i < this->d->iQuantLayer; i++)
for (int j = 0; j < this->d->piQuantNInLayer[i]; j++)
for (int k = 0; k < this->d->piQuantNInLayer[i - 1]; k++) {
::SetFilePointer(this->file, fl, 0, FILE_CURRENT);
::ReadFile(this->file,
&this->d->pppdWeights[i][j][k],
sizeof double(1),
&fl,
NULL);
}
}