title: how to use getline correctly
body: <p>I wrote a program that uses <code>getline()</code> function, but I don't know how should I use <code>getline()</code> in the correct way. I've searched it on the Internet but I just found something about about using <code>getchar()</code> with <code>getline()</code> or <code>cin.ignore()</code>. I tried and none of them worked and I don't know what is the problem and why <code>getline()</code> function needs <code>getchar()</code> or <code>cin.ignore()</code> to work correctly?   </p>
  
  <p>My Input  </p>
  
  <pre><code>2   
  Alderaan   
  1000.00 2000.00 3000.00   
  Dantooine   
  -1000.00 1000.00 1000.00   
  Circarpous Major   
  -500.00 500.00 -500.00   
  Y’Toub   
  -500.00 -500.00 500.00    
  </code></pre>
  
  <p>here is my code:  </p>
  
  <pre><code>#include &lt;cmath&gt;
  #include &lt;string&gt;
  #include &lt;cstdio&gt;
  #include &lt;iostream&gt;
  using namespace std;
  int main()
  {
      long long int  x, y, z, x1, y1, z1;
      int n;
      cin &gt;&gt; n;
      string s, p;
      while (n--)
      {
          getline(cin, s);
          cin &gt;&gt; x;
          cin &gt;&gt; y;
          cin &gt;&gt; z; 
          cin.ignore();
          getline(cin, p);
          cin &gt;&gt; x1;
          cin &gt;&gt; y1;
          cin &gt;&gt; z1;
          cin.ignore();
          printf("%s to %s: %.2f\n", s.c_str(), p.c_str(), sqrt(pow(x - x1, 2) + pow(y - y1, 2) + pow(z - z1, 2)));
      }
  }
  </code></pre>