I am using std::fstream for opening binary file and reading/writing in it. I try to work with blocks, so I must read and write. But in std::fstream::seekp program send exception: Unhandled exception at 0x00007FFE5152D85E (ntdll.dll) in gridfile.exe: 0xC0000005: Access violation writing location 0x0000000000000024. I am using MSVS 2013.
It fall in method _Lock() in std::basic_streambuf. Is there some rules how can I make both operations?
Open code:
file.open(filename,
std::fstream::out | std::fstream::in | std::fstream::binary | std::fstream::trunc);
Write header code:
file.seekp(0);
file.write((char*) &(header.blockCount), sizeof(header.blockCount));
file.write((char*) &(header.blockSize), sizeof(header.blockSize));
file.flush();
Read header code:
file.seekg(0);
file.read((char*) &(header.blockCount), sizeof(header.blockCount));
file.read((char*) &(header.blockSize), sizeof(header.blockSize));
Method for writing/reading other types of block are +/- same. Operations order is Seek -> write(read) -> flush(after write).
Error is in seekp in writing. Thank for your answer.
Aucun commentaire:
Enregistrer un commentaire