I have two streams, one to read from and one to write to (diff. files).
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);
Appending data to the file works fine, until it gets to a write operation with a std::streamoff
variable.
Taking into account that it is a std::wofstream
, I output the variable "normally" as I did it already a few times in this function.
//[...]
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
What could cause this issue ?
Note that this works fine if I use a std::ofstream
instead.