Bug 27678 - ofstream() << C-string prints the pointer address.
Summary: ofstream() << C-string prints the pointer address.
Status: RESOLVED DUPLICATE of bug 9925
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-19 13:26 UTC by Yotam Medini
Modified: 2006-05-19 16:35 UTC (History)
9 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yotam Medini 2006-05-19 13:26:38 UTC
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>
Comment 1 Andrew Pinski 2006-05-19 16:35:50 UTC

*** This bug has been marked as a duplicate of 9925 ***