This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

a further question


Hi,

I'm Graziano Servizi.

I wrote to you five days ago (by the way I didn't yet receice any answer) and I have one more question, about the C++ I/O library in the
4.8.2 version of the compiler.

In an I/O stream (declared as an instance of fstream and opened for
both INPUT and OUTPUT accesses) the so called "get" and "put" areas are driven through TWO distinct indicators, independent from each other, OR
aren't?

In the following short code

// code begins
# include <iostream>
# include <fstream>
using namespace std;


int main(  )
 {
  fstream f("file", ios::in | ios :: out | ios :: app | ios :: binary);
  char z = 'Z', c;
  f . get(c);
  cout << c << endl;
  f . put(z);
  f . seekp(4);
  f . get(c);
  cout << c << endl;
  f . put(z);
 }

// code ends

where "file" is a disk file containing just
the 26 lowercase letters and a single trailing newline (file size = 27 bytes), I got the following standard output
a
e
while the "file" got two capital Z's appended.
I would expect that, since the stream is opened in ios::app mode for
writing, hence the f.seekp(4) would correctly be IGNORED.

But why the second f.get(c) yields c == e ?
Nobody moved (I suppose) the indicator of the "get" area (or not?).
I expected 'b' as the value got for c in the second call of the get function... where am I wrong? It appears that seekp has moved the
get indicator as it would be done if seekg would be called...

In addition I NEVER have understood the usefulness of the ios :: binary
openmode flag: I always (ALWAYS, in my tests, I mean) got the SAME behaviour regardless of its presence or absence...included the present
case.

Sorry for my (may be) pedantic questions, but YOU said in the web pages
that any testing of the compiler is welcome...

                                 G. Servizi
                                 Associate Professor
                                 of Mathematical Physics
                                 University of Bologna




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]