title: C++ - Am I using fin.ignore() incorrectly?
body: <p>I have a .txt file called "1.txt" that I want to read in.  Since the file starts with 8 BOM characters, if I do the following:</p>
  
  <pre><code>ifstream fin("1.txt");
  
  string temp = "";
  
  char c = fin.get();
  
      while (!fin.eof())
      {
          if (c &gt;= ' ' &amp;&amp; c &lt;= 'z')
          {
              temp += c;
          }
  
          c = fin.get();
      }
  
      cout &lt;&lt; temp;
  </code></pre>
  
  <p>This will print nothing, because of something the BOM is doing.</p>
  
  <p>So, I decided to use the fin.ignore() function, in order to ignore the beginning BOM characters of the file.  However, still nothing is being printed.  Here is my complete program:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;istream&gt;
  
  using namespace std;
  
  int main()
  {
  ifstream fin("1.txt");
  
  if (fin.fail())
  {
      cout &lt;&lt; "Fail\n";
  }
  
  else
  {
      string temp = ""; // Will hold 1.txt's contents.
  
      fin.ignore(10, ' ');
      // Ignore first 10 chars of the file or stop at the first space char,
      // since the BOM at the beginning is causing problems for fin to read the file.
      // BOM is 8 chars, I wrote 10 to just be safe.
  
      char c = fin.get();
  
      while (!fin.eof())
      {
          if (c &gt;= ' ' &amp;&amp; c &lt;= 'z') // checks if c stores a standard char.
          {
              temp += c;
          }
  
          c = fin.get();
      }
  
      cout &lt;&lt; temp;
  
      // PROBLEM:  No text is printed to the screen from the above command.
  
      cout &lt;&lt; temp.size(); // prints 0
  }
  }
  </code></pre>
  
  <p>I hypothesize that after the:  ifstream fin("1.txt");  line, it is already too late, since the BOM probably affected things with fin then.  So I need to somehow tell fin to ignore the BOM characters before it reads in the file, but I can't use fin.ignore() since I wouldn't have declared a fin object yet.</p>
  
  <p>Also, I know I can manually delete the BOM from my .txt file, but I'm looking for a solution that only involves me writing a C++ program.  If I have thousands or millions of .txt files, deleting manually is not an option.  Also, I'm not looking to download new software, like Notepad++</p>
  
  <p>Here is all I have in the file  "1.txt":</p>
  
  <blockquote>
    <p>ÐÏà¡±á   Hello!</p>
  </blockquote>
  
  <p>This site's formatting doesn't let me show it, but in the actual file there are about 15 spaces between the BOM and Hello!</p>