Reputation: 305
I am writing to a file in C++ in append mode, the program which I am using for the same is:
#include <fstream>
void main()
{
ofstream f;
f.open("f.txt", ios::app);
f<<"\n Hello";
f.close();
}
Now the output which is getting printed in the output file is some thing junk...which I can't comprehend:
OUTPUT:
牐湩㩴
Please help me as to where am i going wrong??? I am working on linux.
Upvotes: 0
Views: 106
Reputation: 39461
This is because you didn't specify a text encoding, and in the absence of explicit encoding markings, Windows just guesses. The most famous instance of this is Bush Hid The Facts
Upvotes: 1
Reputation: 308520
The file which you are appending to has a BOM marker indicating it is UTF-16 encoded. Recreate the file using an editor which will not encode the file, or use a program to write it from scratch.
Upvotes: 1