title: Ignore byte-order marks in C++, reading from a stream
body: <p>I have a function to read the value of one variable (integer, double, or boolean) on a single line in an <code>ifstream</code>:</p>
  
  <pre><code>template &lt;typename Type&gt;
  void readFromFile (ifstream &amp;in, Type &amp;val)
  {
    string str;
    getline (in, str);
    stringstream ss(str);
    ss &gt;&gt; val;
  }
  </code></pre>
  
  <p>However, it fails on text files created with editors inserting a BOM (<a href="http://en.wikipedia.org/wiki/Byte_order_mark" rel="noreferrer">byte order mark</a>) at the beginning of the first line, which unfortunately includes {Note,Word}pad. How can I modify this function to ignore the byte-order mark if present at the beginning of <code>str</code>?</p>