title: Problem reading 2 integers and a string from a file
body: <pre><code>#include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;limits&gt;
  
  using namespace std;
  
  ifstream fin ("tv.in");
  ofstream fout("tv.out");
  
  struct time {
      int PublicityTime;
      int hh, mm, ss;
  };
  
  void getTime(const string&amp; s, time&amp; t) {
      int x = 0;
      int i = 0;
  
      for (;s[i] != ' ';i ++)
          x = x * 10 + s[i] - '0';
  
      i ++;
  
      t.PublicityTime = x;
  
      x = 0;
  
      for (;s[i] != ':';i ++)
          x = x * 10 + s[i] - '0';
  
      i ++;
  
      t.hh = x;
  
      x = 0;
  
      for (;s[i] != ':';i ++)
          x = x * 10 + s[i] - '0';
  
      i ++;
  
      t.mm = x;
  
      x = 0;
  
      for (;i &lt; s.size();i ++)
          x = x * 10 + s[i] - '0';
  
      t.ss = x;
  }
  
  int main() {
      int q, n;
      char c;
      string s;
      time arr[100];
  
      fin &gt;&gt; q;
      fin &gt;&gt; n;
  
      for (int i = 1;i &lt;= n;i ++) {
          getline(fin, s);
  
          fout &lt;&lt; s &lt;&lt; '\n';
          getTime(s, arr[i]);
      }   
  
      return 0;
  }
  </code></pre>
  
  <p>I want to read from a file that looks something like this</p>
  
  <pre><code>6
  1
  120 12:00:00
  200 12:01:50
  1000 13:00:00
  2000 13:01:00
  100 14:05:05
  10 23:59:49
  </code></pre>
  
  <p>if i run the above code for the this file,i will get something like this</p>
  
  <pre><code>94217584 -1388646703:121:0
  120 12:0:0
  200 12:1:50
  1000 13:0:0
  2000 13:1:0
  100 14:5:5
  </code></pre>
  
  <p>Can someone help undestand what is happening ?
  I've searched on google in order to find what would cause such an error and found that the problem would be that there are some '\n' that remain in the buffer, because the file looks something like this:
  "6\n1\n120 12:00:00\n200 12:01:50\n1000 13:00:00\n2000 13:01:00\n100 14:05:05\n10 23:59:49"
  I tried extracting both '\n' but the problem still isn't solved.</p>
  
  <pre><code>fin &gt;&gt; n;
  fin &gt;&gt; c;
  fin &gt;&gt; q;
  fin &gt;&gt; c;
  </code></pre>