Re: std::ostringstream unexpected behavior with .net 2003.

Discussion in 'C++' started by Russell Hanneken, Jun 25, 2003.

  1. "Nathalie D'Amours" <> wrote in message
    news:vVoKa.4091$...
    >
    > int i = 3;
    > std::eek:stringstream 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
    Russell Hanneken, Jun 25, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Victor Bazarov
    Replies:
    0
    Views:
    844
    Victor Bazarov
    Jun 25, 2003
  2. Chris
    Replies:
    3
    Views:
    2,015
    Chris
    Feb 17, 2004
  3. Jason Heyes
    Replies:
    1
    Views:
    2,615
    Shezan Baig
    Feb 6, 2005
  4. Bala2508
    Replies:
    28
    Views:
    1,167
    Jim Langston
    Nov 3, 2007
  5. Pallav singh
    Replies:
    3
    Views:
    4,016
    Saeed Amrollahi
    Oct 21, 2009
Loading...

Share This Page