title: Issue with cin when spaces are inputted, using string class
body: <p>I have the following code:</p>
  <h1>main.cpp</h1>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  string name;
  string age;
  
  int main() {
      cout &lt;&lt;&quot;Name: &quot;;
      cin &gt;&gt; name;
      cout &lt;&lt; endl;
      cout &lt;&lt;&quot;Age: &quot;;
      cin &gt;&gt; age;
      cout &lt;&lt; endl;
      cout &lt;&lt; &quot;Your name is &quot; &lt;&lt; name &lt;&lt; &quot;, and you are &quot; &lt;&lt; age &lt;&lt; &quot; years old.&quot;  &lt;&lt; endl;
      cout &lt;&lt; &quot;Press enter to close this application&quot; &lt;&lt; endl;
      getchar();
      return 0;
  }
  </code></pre>
  <p>I noticed that if I put a space in my input for name that it won't give me a chance to input name, and it will view the entry after the space as age. I apologize if this is a newbie mistake, which it probably is. I previously programmed Java and decided I wanted to switch to C++ because it better suits my needs. I also probably format my code weird to your standards, please correct it if you wish to.</p>
  <p><img src="https://i.stack.imgur.com/uym9y.png" alt="Screenshot of console" /></p>
  <p>I've also noticed another error, something I never really had any problems with in Java. I can't figure out how to prevent it from instantly closing down when it finishes processing. I've heard you can use &quot;system.(&quot;pause&quot;); but I've also been told to not use it. I'm really confused on what to use. I've heard to use getchar();, but it doesn't seem to do anything.</p>
  <p>Any help would be greatly appreciated, as I'm a complete beginner when it comes to C++.</p>