title: Read from stdin in C++
body: <p>Here is my code:</p>
  
  <pre><code>...
  ...
  do
  {
      cin &gt;&gt; command;
  
      switch(command)
      {
          case 'i':
              cin &gt;&gt; key &gt;&gt; nome &gt;&gt; idade &gt;&gt; endereco;
              count++;
  
              pessoas = (Pessoa **) realloc(pessoas, count*sizeof(Pessoa *));
              pessoas[count-1] = new Pessoa(key, nome, idade, endereco);
  
              bTree-&gt;add(pessoas[count-1]);
              break;
  
          case 's':
              cin &gt;&gt; key;
  
              toSearch = (Pessoa *) bTree-&gt;search(key);
  
              if(toSearch == NULL)
              {
                  cout &lt;&lt; "-1" &lt;&lt; endl;
              }
              else
              {
                  cout &lt;&lt; key &lt;&lt; endl;
                  cout &lt;&lt; toSearch-&gt;getNome() &lt;&lt; endl;
                  cout &lt;&lt; toSearch-&gt;getIdade() &lt;&lt; endl;
                  cout &lt;&lt; toSearch-&gt;getEndereco() &lt;&lt; endl;
              }
  
              break;
  
          case 'e':
              done = true;
              break;
      }
  
  } while(!done);
  ...
  ...
  </code></pre>
  
  <p>I have a "menu" that when I enter <code>i</code>, it will insert in BTree, <code>s</code> will search and <code>e</code> will exit the program.</p>
  
  <p>The problem is, when I hit <code>i</code> to insert, I have to give four parameters:</p>
  
  <ol>
  <li>(int) Key;</li>
  <li>(string) Name;</li>
  <li>(int) Age;</li>
  <li>(string) Address;</li>
  </ol>
  
  <p>When I give a name that have an <code>e</code> character inside (eg. "James"), it will exit the program.</p>
  
  <p>How do I avoid <code>command</code> to read the stdin buffer while I'm reading it on switch?</p>
  
  <p>Sample input:</p>
  
  <pre><code>i
  1
  Joao da Silva 1
  11
  Rua 2, 3
  i
  2
  Joao da Silva 2
  12
  Rua 4, 6
  s
  1
  s
  7
  e
  </code></pre>
  
  <p>Thanks.</p>