Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次のコードに問題があります。
fstream s("tst.txt" , fstream::binary); s.seekp(5, fstream::beg); s.write("testing", 7);
ファイルの最初の 5 文字をそのまま保持する必要がありますが、そうではありません。古いデータ全体を破棄します。古いデータを保持し、ファイル データのブロックだけを上書きする必要があります。バイナリ モードにする必要があります。前もって感謝します。
これを試して:
fstream s("tst.txt" , fstream::binary | fstream::in | fstream::out); s.seekp(5, std::fstream::beg); s.write("testing", 7);
openmode フラグを指定することにより、fstream コンストラクター呼び出しでデフォルトの openmode をオーバーライドします。