파일의 일부를 이진 모드로 바꾸는 데 문제가 있습니다. 어떤 이유로 내 seekp() 줄이 파일 포인터를 원하는 위치에 놓지 않습니다. 지금은 원하는 부분을 대체하는 대신 파일의 끝에 새 내용을 추가합니다.이진 모드에서 파일의 일부를 바꾸는 데 seekp() 문제가 발생했습니다.
long int pos;
bool found = false;
fstream file(fileName, ios::binary|ios::out|ios::in);
file.read(reinterpret_cast<char *>(&record), sizeof(Person));
while (!file.eof())
{
if (record.getNumber() == number) {
pos=file.tellg();
found = true;
break;
}
// the record object is updated here
file.seekp(pos, ios::beg); //this is not placing the file pointer at the desired place
file.write(reinterpret_cast<const char *>(&record), sizeof(Person));
cout << "Record updated." << endl;
file.close();
내가 잘못하고 있나?
미리 감사드립니다.