我有两个流,一个要读取,一个要写入(差异文件)。
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
将数据附加到文件工作正常,直到它使用变量进行写入操作。考虑到它是 a 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
什么可能导致这个问题?
请注意,如果我使用 astd::ofstream
代替,这可以正常工作。