Not sure if this is the right forum for what could be a windows bug.
Running the following code compiled with VC14 and running on windows 10 gives different results depending on whether the executable is on the C: drive or an external USB drive:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <fstream>
usingnamespace std;
int main()
{
{
ofstream out ("test.txt", ios::out | ios::binary);
out << "1234567890" << endl;
}
{
ofstream out ("test.txt", ios::out | ios::binary);
out << "abcdef" << endl;
}
return 0;
}
Output when run on the C: drive:
abcdef
Output when run on the D: USB drive:
abcdef
890
It appears than when writing to an external drive, it doesn't truncate the file if the new content is shorter than the original.
Watch out for this kind of errors as they can spend a lot of your time discovering them. If you need some help you can try using some programs like checkmarx or others but it's recommended to do it on your own.
Good luck!
Ben.