It looks lengthy, but it is easier to read. Please keep patience.
Here is a simple C++ program, from the book C++ the complete reference: 4th edition (chapter 21, page 543), which writes a text file:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream out("INVNTRY.txt"); // output, normal file
if(!out) {
cout << "Cannot open INVENTORY file.\n";
return 1;
}
out << "Radios " << 39.95 << endl;
out << "Toasters " << 19.95 << endl;
out << "Mixers " << 24.80 << endl;
out.close();
system("pause");
return 0;
}
and another program that reads the data just written:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream in("INVNTRY.txt"); // input
if(!in) {
cout << "Cannot open INVENTORY file.\n";
return 1;
}
char item[20];
float cost;
in >> item >> cost;
cout << item << " " << cost << "\n";
in >> item >> cost;
cout << item << " " << cost << "\n";
in >> item >> cost;
cout << item << " " << cost << "\n";
in.close();
system("pause");
return 0;
}
Everything is fine, till now. Whatever was written, is easily readable.
Now the problem is, I have written another text file "response.txt" using Visual Basic. I tried to read the file using the above program. But in console window i got " " at the very beginning!
I thought something was wrong with my "response.txt" file, I copied the content of "INVNTRY.txt" and pasted in "response.txt", but still got " " at the beginning. How is this possible. At this point of time, two files have the same content, same program was used to read them, still different output ??
I am trying to show some pictures for clarification:

But if I try to read "INVNTRY.txt", look the difference in output, there is no " " character at the beginning:

How is this possible ??
System.Text.ASCIIEncoding. The default isSystem.Text.UTF8Encoding, and is responsible for your BOM woes.