ostrstream

This is a discussion on ostrstream within the C++ Programming forums, part of the General Programming Boards category; Hello everyone, The situation when we need to use this class is, we want to continue to append the content ...

  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
    dra
    dra is offline
    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
    dra
    dra is offline
    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
    22,256
    ostrstream is deprecated.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    22,256
    For what reason?
    I do not know, but I do know that std::ostringstream would be the corresponding non-deprecated class.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    dra
    dra is offline
    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
    22,256
    Do you know where to find a sample of this class?
    This article seems good:
    Stream Thy Strings
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    22,256
    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".
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21