The following example should be self explanatory. I was expecting same content to be written onto the files "goodstr.txt" and "whyptr.txt". -- yotam yotam@durini:C:444> g++ -v Using built-in specs. Target: i486-linux-gnu Configured with: ../src/configure -v --enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr --with-gxx-include-dir=/usr/include/c++/4.0.2 --enable-shared --with-system-zlib --libexecdir=/usr/lib --enable-nls --without-included-gettext --enable-threads=posix --program-suffix=-4.0 --enable-__cxa_atexit --enable-libstdcxx-allocator=mt --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr --disable-werror --enable-checking=release i486-linux-gnu Thread model: posix gcc version 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu9) yotam@durini:C:445> cat ofstream-bug.cc #include <fstream> using namespace std; int main(int, char**) { static const char* magic = "flute"; { ofstream ofs("goodstr.txt"); ofs << magic; } { ofstream("whyptr.txt") << magic; } return 0; } yotam@durini:C:446> g++ -Wall -o /tmp/x ofstream-bug.cc yotam@durini:C:447> ldd /tmp/x; ls -l /tmp/x linux-gate.so.1 => (0xffffe000) libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb7e2e000) libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7e0c000) libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb7e01000) libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7cd3000) /lib/ld-linux.so.2 (0xb7f25000) -rwxr-xr-x 1 yotam yotam 8777 2006-05-19 16:18 /tmp/x* yotam@durini:C:448> /tmp/x yotam@durini:C:449> cat goodstr.txt; echo"" flute yotam@durini:C:450> cat whyptr.txt; echo"" 0x804883c yotam@durini:C:451>
*** This bug has been marked as a duplicate of 9925 ***