In the program you need to replace the number in the binary file. There was a problem with the replacement function. It reads not a number, but it’s not clear that, besides, it does not move to a new position, keeping the first megadlinal value, which should not be.
for example, written to a file:
0 3 третий 2 пятый 0 первый 4 второй 1 if I decide to add a четвёртый 2 , the deuce near the третий should change to 5.
Code:
void swap_val(fstream&tab){ int buf; tab.open("tab.bin", ios::in | ios::out | ios::binary); for(int i = 21; i < block*(k-1); i+=block){ tab.seekg(i); tab.read((char*)&buf, 4); cout << "buf: " << buf << endl; if(buf == val){ tab.seekg(i); tab.write((char*)&val, 4); tab.seekg(block*k - 4); tab.write((char*)&buf, 4); cout << "Check" << endl; break; } } tab.close(); }