title: Line number in a C++ istream?
body: <p>Suppose I'm reading tokens from a <code>std::istream</code>. What is a good way to know the number of newlines that have been read from the stream? This is for the purpose of error reporting in a parser. I don't want to use <code>std::getline</code> to read input.</p>
  
  <p>Here is a test case. I am looking for something functionally similar to <code>GetLineNumber</code>, which in this case would return the line number of the last read token.</p>
  
  <pre><code>std::stringstream ss;
  ss &lt;&lt; "1 \n 2 \n 3 \n";
  
  int x;
  while (ss &gt;&gt; x) {
      std::cout &lt;&lt; "Line " &lt;&lt; GetLineNumber(ss) &lt;&lt; ": " &lt;&lt; x &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>The output to this example should be:</p>
  
  <pre><code>Line 1: 1
  Line 2: 2
  Line 3: 3
  </code></pre>