Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Re: std::ostringstream unexpected behavior with .net 2003. (http://www.velocityreviews.com/forums/t267730-re-std-ostringstream-unexpected-behavior-with-net-2003-a.html)

Russell Hanneken 06-25-2003 10:22 PM

Re: std::ostringstream unexpected behavior with .net 2003.
 
"Nathalie D'Amours" <nathalie.damours@timespring.com> wrote in message
news:vVoKa.4091$Fe3.665943@news20.bellglobal.com.. .
>
> int i = 3;
> std::ostringstream os;
> os << i << std::ends;
> std::string s1 = os.str();
> std::string s2("3");
> bool result = (s1 == s2);
>
> When I execute this code, 'result' gets set to false. Obviously I am
> expecting the strings to be identical. I've stepped in the comparison
> code and the internal call to ::strcmp correctly returns 0 but then there
> is some logic to compare the string lengths and they differ. s1 size is
> 2 and s2 is 1 and this is why the comparison function returns false.
>
> This seems buggy to me. Am I missing something? Has anyone else seen the
> same problem?


s1 is two characters: '3' and std::ends. s2 is one character: '3'.

You shouldn't use std::ends with ostringstreams. std::ends is useful only
with ostrstreams, which are deprecated.

Regards,

Russell Hanneken
rhanneken@pobox.com





All times are GMT. The time now is 01:32 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.