Thread: ostrstream

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    ostrstream

    Hello everyone,


    The situation when we need to use this class is, we want to continue to append the content of string (not at one time, but at many times -- appending). Right?

    Any other situations which use of this class (compared with other string and stream related class) will give us special benefits?


    thanks in advance,
    George

  2. #2
    Weak. dra's Avatar
    Join Date
    Apr 2005
    Posts
    166
    I like it for printing out the contents of a container =P.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks dra,

    You mean something like this,

    Code:
    ostrstream sout;
    Loop for each elements in container
    {
        sout << element [i];
    }
    
    sout.str();
    Quote Originally Posted by dra View Post
    I like it for printing out the contents of a container =P.

    regards,
    George

  4. #4
    Weak. dra's Avatar
    Join Date
    Apr 2005
    Posts
    166
    usually with std::copy in <algorithm>

    Code:
    std::copy(vec.begin(), vec.end(), std::ostream_iterator<DataType>(cout, " "));
    beats writing a while loop =/

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Hi dra,


    Your code below does not use ostrstream at all, and we are discussing about ostrstream in this thread. :-)

    Any ideas to my original question?

    Quote Originally Posted by dra View Post
    usually with std::copy in <algorithm>

    Code:
    std::copy(vec.begin(), vec.end(), std::ostream_iterator<DataType>(cout, " "));
    beats writing a while loop =/

    regards,
    George

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    ostrstream is deprecated.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Hi laserlight,


    For what reason?

    Quote Originally Posted by laserlight View Post
    ostrstream is deprecated.

    regards,
    George

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    For what reason?
    I do not know, but I do know that std::ostringstream would be the corresponding non-deprecated class.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Weak. dra's Avatar
    Join Date
    Apr 2005
    Posts
    166

    Angry

    Quote Originally Posted by George2 View Post
    Hi dra,


    Your code below does not use ostrstream at all, and we are discussing about ostrstream in this thread. :-)

    Any ideas to my original question?




    regards,
    George
    Yeah sorry I apologize, I read your question wrong....

  10. #10
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks laserlight,


    I feel short of knowledge about ostringstream, then I searched MSDN, but find very little information. Do you know where to find a sample of this class?

    Quote Originally Posted by laserlight View Post
    I do not know, but I do know that std::ostringstream would be the corresponding non-deprecated class.

    regards,
    George

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Do you know where to find a sample of this class?
    This article seems good:
    Stream Thy Strings
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks laserlight,


    Looks good. :-)

    Quote Originally Posted by laserlight View Post
    This article seems good:
    Stream Thy Strings

    regards,
    George

  13. #13
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Sorry for interrupting again, laserlight!


    Do you have a formal link or document describing ostrstream is outdate and we should use ostrstring to replace it? :-)

    Quote Originally Posted by laserlight View Post
    This article seems good:
    Stream Thy Strings

    regards,
    George

  14. #14
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Do you have a formal link or document describing ostrstream is outdate and we should use ostrstring to replace it? :-)
    Yes, namely the C++ Standard (2003 edition) Annex D.6

    Oh, and "ostrstring" should be "ostringstream".
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  15. #15
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks laserlight,


    My question is answered.

    Quote Originally Posted by laserlight View Post
    Yes, namely the C++ Standard (2003 edition) Annex D.6

    Oh, and "ostrstring" should be "ostringstream".

    regards,
    George

Popular pages Recent additions subscribe to a feed