stringstream strange output

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • drusakov

    stringstream strange output

    consider the following piece of code, compiled with g++ 3.4 and
    stlport 5.1 on Linux 64 bit (problem persists in 32 bit too)

    std::stringstre am ss;
    int ii = 123;
    ss << "test1";
    std::cout<<ss.s tr()<<std::endl ;
    ss << ii << "test2";
    std::cout << ss.str()<<std:: endl;

    The output I'm getting is quite strange:
    test1
    test1test2

    It like 'ii' is not printed. If I remove line #4, then all is fine and
    I get "test1123te st2" also if to replace 'ii' in line 5 with some
    string, like "test22", you'll get last line "test1test22tes t2" as
    expected.

    drives me crazy. any idea what it can be?

    Thanks,
    Dmitry
  • Jeff Schwab

    #2
    Re: stringstream strange output

    drusakov wrote:
    consider the following piece of code, compiled with g++ 3.4 and
    stlport 5.1 on Linux 64 bit (problem persists in 32 bit too)
    #include <iomanip>
    #include <iostream>
    #include <sstream>

    int main() {
    std::stringstre am ss;
    int ii = 123;
    ss << "test1";
    std::cout<<ss.s tr()<<std::endl ;
    ss << ii << "test2";
    std::cout << ss.str()<<std:: endl;
    }
    The output I'm getting is quite strange:
    test1
    test1test2
    >
    It like 'ii' is not printed. If I remove line #4, then all is fine and
    I get "test1123te st2" also if to replace 'ii' in line 5 with some
    string, like "test22", you'll get last line "test1test22tes t2" as
    expected.
    Is it possible that memory is being corrupted elsewhere in your program?
    What happens when you compile and run the above code as a stand-alone
    program?

    Comment

    • James Kanze

      #3
      Re: stringstream strange output

      On Sep 23, 9:29 pm, drusakov <dmitry.rusa... @googlemail.com wrote:
      consider the following piece of code, compiled with g++ 3.4
      and stlport 5.1 on Linux 64 bit (problem persists in 32 bit
      too)
      Just a question: why? G++ has one of the better library
      implementations around, the STL port is one of the worst. So
      why use it with g++?
      std::stringstre am ss;
      int ii = 123;
      ss << "test1";
      std::cout<<ss.s tr()<<std::endl ;
      ss << ii << "test2";
      std::cout << ss.str()<<std:: endl;
      The output I'm getting is quite strange:
      test1
      test1test2
      It like 'ii' is not printed. If I remove line #4, then all is fine and
      I get "test1123te st2" also if to replace 'ii' in line 5 with some
      string, like "test22", you'll get last line "test1test22tes t2" as
      expected.
      drives me crazy. any idea what it can be?
      It would seem to be a bug in the STL. The above code works with
      the default libraries with g++, Sun CC and VC++; I get the same
      symptoms as you with Sun CC and the STL port, however.

      --
      James Kanze (GABI Software) email:james.kan ze@gmail.com
      Conseils en informatique orientée objet/
      Beratung in objektorientier ter Datenverarbeitu ng
      9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

      Comment

      Working...