public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* cout Issue
@ 2009-05-12  6:33 Arthur Schwarz
  2009-05-12  8:32 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Arthur Schwarz @ 2009-05-12  6:33 UTC (permalink / raw)
  To: gcc


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>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-05-12  8:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-12  6:33 cout Issue Arthur Schwarz
2009-05-12  8:32 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).