C++ でバイナリ ファイルを作成しています。特定の場所にトラバースし、その内容を新しい場所で上書きする必要があります。整数サイズの中身はわかっているので、場所を追って上書きしていきます。ofstream 書き込み関数が変数を挿入または追加するようです。ファイルに追加または挿入する代わりに、上書きできる方法はありますか
long word = sizeof(int) + sizeof(long) + sizeof(long);
std::ofstream file_write(filename, std::ios::out|std::ios::binary);
file_write.seekp(word);
long pos = file_write.tellp();
file_write.write((char *)&some_integer,sizeof(int));
file_write.close()
//some other location
file_write.seekp(pos);
file_write.write((char *)&some_other_integer,sizeof(int));
//ここで、some_integer は some_other_integer で上書きする必要があります。それを行う方法はありますか?
それは次のようになります
値1,値2,値3
値 2 を値 5 に置き換えることができるかもしれません。
それは次のようになります
値1、値5、値3