title: Why doesn't the getline() function read anything here?
body: <p>For the input,</p>
  
  <pre><code>1
  4 2
  1 2
  1 3
  1
  </code></pre>
  
  <p>The Program,</p>
  
  <pre><code>#include &lt;cmath&gt;
  #include &lt;cstdio&gt;
  #include &lt;vector&gt;
  #include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  using namespace std;
  
  
  int main() 
  {
    int Q;
    cin &gt;&gt; Q;   //Q=2
  
    while(Q--)
    {
      int N, E;
      cin &gt;&gt; N &gt;&gt; E;  // N=4, E=2    
  
      while(1)
      {
        string edge;
        getline(cin,edge); //edge should store "1 2" for the first iteration and "1 3" for the second iteration.
        cout &lt;&lt; edge &lt;&lt; " " &lt;&lt; edge.size() &lt;&lt; endl;
        vector&lt;int&gt; adjList[N];
  
        if(edge.size()&gt;1)
        {
          int u = stoi(edge.substr(0,1));
          int v = stoi(edge.substr(2,1));
  
          for(int i=0; i&lt;E; ++i)
          {
            adjList[u].push_back(v);
            adjList[v].push_back(u);
          }
        }
  
        else
          break;
      }
    }
  
    return 0;
  }
  </code></pre>
  
  <p>gives output</p>
  
  <pre><code>0
  </code></pre>
  
  <p>The program should print out,</p>
  
  <pre><code>1 2 3
  1 3 3
  1 1
  </code></pre>
  
  <p>Why am I not storing any value in the string <strong>edge</strong>? I think it's the <code>getline()</code> function which causes the problem. Are there other functions that can take the whole line as into a string (including spaces) until a newline is reached?</p>