Program and particulars below.

When line 27 is commented out, line 26 is output. When line 27 is not 
commented, line 26 is not output except that if x.file contains a line feed the 
null line line 26 & line 27 are output. If x.file does not contain a line feed, 
only line 27 is output.

Does the line feed have an effect on the 'cout <<' of line 26 of the program?

Note. The code is awful and this is an example.

art

g++-4 (GCC) 4.3.2 20080827 (beta) 2


x.cpp

      1 # include <ios>
      2 # include <iomanip>
      3 # include <fstream>
      4 # include <iostream>
      5 # include <sstream>
      6
      7 using namespace std;
      8
      9 ifstream  x("x.file", ios::in);
     10
     11 struct y {
     12   double a;
     13   double b;
     14 } yNot;
     15
     16 int main(int argc, char** argv) {
     17   char  Line[512];
     18   long  LineNo = 0;
     19   while ( !x.eof() ) {
     20      LineNo++;
     21      x.getline(Line, 512);
     22      istringstream Phfft(Line);
     23        yNot.a = -1;
     24        yNot.b = -2;
     25        Phfft >> yNot.a >> yNot.b;
     26        cout << setw(4) << LineNo << ": " << Line;
     27        cout << "   a:" << yNot.a << "  b:" << yNot.b;
     28      cout << endl;
     29   }
     30   return 0;
     31 }

x.file
1 2<lf>
<nada>

Reply via email to