#include <iostream>
#include <fstream>
using namespace std;
void main() {
/*int A[20]{ 3,7,3,2,4,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 };
ofstream fout("D://text//1.txt", ios_base::ate | ios_base::binary);
if (fout.is_open()) {
fout.write((char*)A, sizeof(A));
}
fout.close();
int B[20] = { 0 };
fstream fin("D://text//1.txt", ios_base::in | ios_base::binary);
if (fin.is_open()) {
fin.read((char*)B, sizeof(B));
}
fin.close();
for (int i = 0; i < 20; i++) {
cout << B[i] << " ";
}*/
int a = 888, b = 4, tmp, j = 0, p;
fstream f("D://text//1.txt", ios_base::app | ios_base::in | ios_base::binary);
if (f.is_open()) {
f.seekp(ios_base::beg);
for (int i = 0; i < 20; i++) {
p = f.tellp();
f.read((char*)&tmp, sizeof(tmp));
if (tmp == b) {
f.write((char*)&a, sizeof(a));
f.flush();
j = 2;
}
else {
j = 1;
}
if (j == 1) {
f.seekp(sizeof(int)*p, ios_base::beg);
}
if (j == 2) {
f.seekg(sizeof(int)*p - 1, ios_base::beg);
}
}
int B[20] = { 0 };
f.read((char*)B, sizeof(B));
f.close();
for (int i = 0; i < 20; i++) {
cout << B[i] << " ";
}
}
system("pause");
}