Why are you using fstream
instead of ofstream
?
The default for fstream
is to open an existing file. The default for ofstream
is to start with an empty file. Whatever is already in the file is probably causing your editor to interpret the data with the wrong encoding.