This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
fstream behaviour error / wrong installation ?
- From: Stephane MILLET <stephane dot millet at dassault-aviation dot fr>
- To: gcc at gcc dot gnu dot org
- Date: Thu, 22 Jan 2004 09:49:58 +0100
- Subject: fstream behaviour error / wrong installation ?
- Reply-to: stephane dot millet at dassault-aviation dot com
Hello,
Hope I'm on the right list for this kind of problem, if not sorry.
My problem: i wrote the following very simple program, but the output is
wrong, if you have any idea, is it my installation or something i don't
understand ?
#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
#include <list>
using namespace std;
main(int argn, char**argc) {
string sbuff = "123456789012345678901234567890";
ofstream toto;
toto.open("toto",ios::out);
toto.write( sbuff.c_str() , 25);
toto.close();
toto.open("toto",ios::ate);
toto.seekp(20,ios::beg);
toto.write( sbuff.c_str() , 25);
toto.close();
}
The expected behaviour was :
* open a file, write 25 bytes, close it, re-open for adding, set
position 20 from beginning, write 25 more bytes
But the actual output is :
$ od -a toto
0000000 nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul
0000020 nul nul nul nul 1 2 3 4 5 6 7 8 9 0 1 2
0000040 3 4 5 6 7 8 9 0 1 2 3 4 5
I compiled and ran the code as follow :
$ g++ toto.cc
$ ldd ./a.out
libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x007e2000)
libm.so.6 => /lib/tls/libm.so.6 (0x00516000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x007d8000)
libc.so.6 => /lib/tls/libc.so.6 (0x003db000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x003c3000)
$ uname -a
Linux pingu 2.4.22-1.2115.nptlsmp #1 SMP Wed Oct 29 15:30:09 EST 2003
i686 i686 i386 GNU/Linux
$ g++ --version
g++ (GCC) 3.3.2 20031022 (Red Hat Linux 3.3.2-1)
Thank you
Regards
Stephane MILLET