title: C++ read file only gives first word
body: <p>I know that I shouldn't use namespace std (<code>using namespace std</code>) as global in this scope, but for this example, I will. </p>
  
  <p>What I ideally want, is to save text to a .txt file and retrieve it. I know that the <strong>best</strong> option would be <code>fstream</code> and so I decided to use it. </p>
  
  <p>The below code prints out "This". Why does it print out "This" and not the full text?</p>
  
  <p>Here is the code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  int main() {
      ifstream fin;
      ofstream fout;
      string text;
  
      fout.open("C++_text_file_test.txt");
      fout &lt;&lt; "This is basic text";
      fout.close();
  
      fin.open("C++_text_file_test.txt");
      fin &gt;&gt; text;
      fin.close();
  
      cout &lt;&lt; text &lt;&lt; endl;
      cin.get(); // waits for user to press enter 
  
      return 0;
  }
  </code></pre>
  
  <p>I tried researching but didn't quite understand the process of using a loop. Is there an easier way or can someone please explain it? </p>