title: opening an ifstream file in C++
body: <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  using namespace std;
  
  int main() {
      string txt="";
      ifstream file;
      file.open ("ernio.txt", ios::in);
      if (file.is_open()) {
          while (getline(file, txt)) {
              cout &lt;&lt; txt &lt;&lt; endl;
          }
      }
      else
          cout &lt;&lt; "example" &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>It prints <code>example</code> instead of reading line by line from the file. What am I doing wrong?!? (the file is in the exact same place as the main.cpp) We even tried:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  using namespace std;
  
  int main() {
      string txt="";
      ifstream file("ernio.txt");
      if (file.is_open()) {
          while (getline(file, txt)) {
              cout &lt;&lt; txt &lt;&lt; endl;
          }
      }
      else
          cout &lt;&lt; "example" &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>Please help</p>