title: Why I am getting this error in c++ code
body: <p>I have this simple code:</p>
  
  <pre><code>std::ifstream ifs;
  ifs.open ("test.txt", std::ifstream::in);
  char c = ifs.get();
  while (ifs.good()) {
     std::cout &lt;&lt; c;
     c = ifs.get();
  }
  ifs.close();
  </code></pre>
  
  <p>But I am getting a lot of error?
  such as:</p>
  
  <pre><code>Error   9   error C3083: 'ifstream': the symbol to the left of a '::' must be a type    test.cpp    
  Error   8   error C2228: left of '.open' must have class/struct/union   test.cpp
  </code></pre>
  
  <p>and so on.</p>
  
  <p>I have these definitions at the start of file</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include "stdafx.h"
  using namespace std;
  </code></pre>
  
  <p>I am using VS2012 on a console application.</p>
  
  <p>edit1:</p>
  
  <p>The complete code is as follow:</p>
  
  <pre><code>void ReadRawImages::Read(int frameNumber)
  {
  std::ifstream ifs;
  
        ifs.open ("test.txt", std::ifstream::in);
  
         char c = ifs.get();
  
         while (ifs.good()) {
              std::cout &lt;&lt; c;
              c = ifs.get();
         }
  
    ifs.close();
  
  
   }
  </code></pre>
  
  <p>I also noted that I have these warnings:</p>
  
  <pre><code>Warning 1   warning C4627: '#include &lt;iostream&gt;': skipped when looking for precompiled header use   test.cpp
  Warning 2   warning C4627: '#include &lt;fstream&gt;': skipped when looking for precompiled header use    test.cpp
  </code></pre>