Igor Mironchik
Igor Mironchik

Reputation: 804

What is the characters at the beginning of std::ifstream?

I open text file with:

std::ifstream in( "1.txt" );

if( in.good() )
{
    char ch = 0;

    while( !in.eof() )
    {
        in >> ch;

        std::cout << std::hex << (short)ch << " ";
    }
}

And I receive three strange characters at the beginning: ffef ffbb ffbf. What is it?

Upvotes: 0

Views: 113

Answers (1)

atlaste
atlaste

Reputation: 31116

It looks like a BOM marker. BOM markers are there to note that your data is UTF-8. Note that ifstream processes things like ASCII.

Best to be careful here: since you're handling it like ASCII, something might go wrong when you encounter a strange character.

See https://en.wikipedia.org/wiki/Byte_order_mark for more details about BOM markers.

Upvotes: 4

Related Questions