Ignore byte-order marks in C++, reading from a stream

前端 未结 2 1965
天涯浪人
天涯浪人 2020-12-16 23:03

I have a function to read the value of one variable (integer, double, or boolean) on a single line in an ifstream:

template 

        
2条回答
  •  萌比男神i
    2020-12-16 23:51

    You have to start by reading the first byte or two of the stream, and deciding whether it is part of a BOM or not. It's a bit of a pain, since you can only putback a single byte, whereas you typically will want to read four. The simplest solution is to open the file, read the initial bytes, memorize how many you need to skip, then seek back to the beginning and skip them.

提交回复
热议问题