title: Why is the C++ StringStream skipping the first number from an input file, but showing the rest?
body: <p>Okay, so I have an input file <code>input.txt</code>that contains a CSV sequence: <code>1,1,1,2,2,3,3,4,4</code> 
  and I am trying to separate it at the commas using a stringstream; however I'm getting a little problem here. For some reason the first number from the sequence is not even getting read by the stream. To show this, I created a some debugging code to see what is happening and I found out that the first number is being stored inside  <code>csvLine</code> and every other number is being read and coverted just fine. I don't understand why just the first number is being omitted. Below is an example pic showing exactly what I mean. <code>num</code> should have the same exact values and <code>Line</code>, but it's not. It has all the values except the first one, which is being stored inside <code>csvLine</code>. Why is this happening?!</p>
  
  <p><img src="https://i.stack.imgur.com/c79CJ.png" alt="program output showing how it skips the first number"></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;sstream&gt;
  using namespace std;
  
  int main(int argc, const char * argv[]) {
      ifstream file;
      string line;
      string csvLine; //comma seperated value line
      int num = 0;
      file.open(argv[1]);
      if(file.is_open()) {
          while(getline(file, line)) { //get the whole line and use string stream to break at commas
              cout &lt;&lt; "\nLine: " &lt;&lt; line &lt;&lt; endl;
              //using stringstream to seperate at commas
              stringstream ss(line);
              while(getline(ss, csvLine, ',')) {
                  cout &lt;&lt; "csvLine: " &lt;&lt; csvLine &lt;&lt; " " &lt;&lt; endl;
                  //using stringstream to convert to int
                  ss &gt;&gt; num;
                  cout &lt;&lt; "num: " &lt;&lt; num &lt;&lt; " " &lt;&lt; endl;
              }
          }
      }
      return 0;
  }
  </code></pre>