2 つのストリームがあり、1 つは読み取り用、もう 1 つは書き込み用 (差分ファイル) です。
std::wofstream origin;
std::wifstream attach;
origin.open(m_SourceFile, std::ios_base::app | std::ios_base::binary);
attach.open(csAttachFilename, std::ios_base::in | std::ios_base::binary);
変数を使用した書き込み操作に到達するまで、ファイルへのデータの追加は正常に機能しstd::streamoffます。であることを考慮してstd::wofstream、この関数ですでに数回行ったように、変数を「通常どおり」出力します。
//[...]
origin.seekp(0, std::ios_base::end); //Go to the end
std::streamoff nOffSet = origin.tellp();
//int nFilenameLength = ...;
origin.write(reinterpret_cast<wchar_t*>(&nFilenameLength), sizeof(nFilenameLength) / sizeof(wchar_t)); //int
//Nothing wrong here
//[...] write more
attach.close();
auto c1 = origin.bad(); //false
origin.write(reinterpret_cast<wchar_t*>(&nOffSet), sizeof(nOffSet) / sizeof(wchar_t));
auto c2 = origin.bad(); //true
//[...] write more
この問題の原因は何ですか? 代わりに
a を使用すると、これは正常に機能することに注意してください。std::ofstream