bug-lib-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is this a bug in G++ STL ?


From: zhangwusheng
Subject: Re: Is this a bug in G++ STL ?
Date: Mon, 16 Sep 2002 00:13:19 +0800

I think you should use the c_str function instead of data because the
string  you get from data doesnot contain the '\0' that indiacte the end of
the string
"Jerry" <address@hidden> wrote in message
news:address@hidden
> I met a strange problem while trying  string class in Standard
> Template Library .
>
> //////////////////////////////////////////////////////
> #include <stdio.h>
> #include <string>
> using namespace std ;
>
> main()
> {
>   string ss = "hello ";
>   {
>     string s1 = ss+ "my Friend";
>     printf("%s\n", s1.data());
>   }
>   {
>     string s2 = ss+ "my God";
>     printf("%s\n", s2.data());
>   }
> }
> //////////////////////////////////////////////////////
>
> When I compile these code using GCC under Linux and FreeBSD, I got a
> result like this:
>
> hello my Friend
> hello my Godend
>
> If I compile the code using MSVC, I got this:
> hello my Friend
> hello my God
>
> Is there a bug in GCC compiler or I was just doing wrong?








reply via email to

[Prev in Thread] Current Thread [Next in Thread]