Menu

ostrstream question

2003-07-04
2012-09-26
  • Nobody/Anonymous

    Hello, I noticed a bad output using the automatic storage allocation
    ostrstream a;

    The problem disappear using the alternative constructor (with fixed buffer dimension)
    ostrstream os(char** buf, int sz, ios::app);

    Using the first constructor it comes wrong chars on my monitor, using Dev-C++.
    The same program compiled with Borland C++ works fine...
    Did anyone detected the same?
    (The sources I used are taken from Bruce Eckel's Thinking C++, so I don't post their)

    Thanks,
    Paolo Ferraresi.

     
    • Anonymous

      Anonymous - 2003-07-04

      Give more information. Use the stringstream class.

      Zero Valintine

      #include <iostream>
      #include <cstdlib>
      #include <sstream>
      using namespace std;

      int main(int argc, char ** argv){
      stringstream a;
      a << "Text: " << "Zero Valintine" << '\n';
      a << "Interger: " << 20 << '\n';
      a << "Float: " << 5.5 << '\n';
      cout << a.str();
      system("PAUSE > NUL");
      return(0);}

       
    • Nobody/Anonymous

      Hello Zero,
      I knew the use of sstream were deprecated, (and Eckel doesn't mention about it in his book).
      I got problems using sstream with Dev-C++ 4 but now I tried and works fine...
      What is the more C++ standard compliant about string stream?

      Thank you!

       
    • aditsu

      aditsu - 2003-07-05

      the standard says: include sstream, and use classes istringstream, ostringstream, and/or stringstream, in the std namespace
      Zero's example is very good

      Adrian

       

Log in to post a comment.

MongoDB Logo MongoDB