title: Console output keeps crashing
body: <p>Trying to solve this <a href="http://ww2.codechef.com/problems/DIRECTI" rel="nofollow">Problem</a>.
  I have written the code which looks like this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  int i,j,n,t;
  
  int main()
  {
  cin&gt;&gt;t;
  
  while(t--)
  {
      vector &lt;string&gt; dr,rd;
      string a,b;
      cin&gt;&gt;n;
      cin.ignore();
  
      for(i=0;i&lt;n;i++)
      {
          a.clear(),b.clear();
          getline(cin,a);
          j=a.find(" on ");
          b=a.substr(j,a.size()-1);
          a.resize(j);
          dr.push_back(a);
          rd.push_back(b);
      }
  
      for(i=0,j=rd.size()-1;i&lt;rd.size();i++,j--)
      {
          cout&lt;&lt;dr[i]&lt;&lt;rd[j]&lt;&lt;endl;
      }
      cout&lt;&lt;endl;
  }
  
  return 0;
  }
  </code></pre>
  
  <p>It works perfectly, at least on the given example when I run it using file I/O(fstream) but when i use console I/O as is the code given it crashes after reading the second number for test case.</p>
  
  <p>Like this:<br/>
  2 <br/>
  4<br/>
  Begin on Road A<br/>
  Right on Road B<br/>
  Right on Road C<br/>
  Left on Road D <em>(reads and prints what should be printed until here)</em><br/>
  6 <em>(reads this and goes to new line)</em><br/>
  <em>(crashes)</em> Begin on Old Madras Road <br/>
  Left on Domlur Flyover<br/>
  Left on 100 Feet Road<br/>
  Right on Sarjapur Road<br/>
  Right on Hosur Road<br/>
  Right on Ganapathi Temple Road<br/></p>
  
  <p>Where is my mistake?</p>