Re: ? How to clear ostringstream buffer

Discussion in 'C++' started by Mark Warren, Jul 23, 2003.

  1. Mark Warren

    Mark Warren Guest

    "Ericcson" <> wrote in message
    news:bflh4j$qdb$...
    > Hi.
    > ----------------------------------------
    > #include <fstream>
    > #include <stdlib.h>
    > #include <sstream>
    > #include <iostream>
    >
    > using namespace std ;
    > int main() {
    > ostringstream myO;
    > myO << 12;
    > cout << "myO = " << myO.str() <<endl;
    > myO << 8;
    > cout << "myO =" << myO.str() <<endl;
    > return 0;
    > }
    > --------------
    >
    > I get :
    > 12
    > 128
    >
    > I would like to get :
    > 12
    > 8
    > i.e to clear the myO buffer before filling it with "8".
    > I don't find how. Could someone help me ?
    >
    > TIA
    > Ericsson
    >
    > PS : the all strory is that I try to convert an integer to a string . I
    > tried itoa(12,s,10) and sprintf(s,"%d",12) with or without c_str() and

    only
    > got compilation errors.
    >


    Use myO.str(""). A non-obvious use and IMHO poor design, a function should
    only have one use.

    Mark
     
    Mark Warren, Jul 23, 2003
    #1
    1. Advertising

  2. Mark Warren

    Ericcson Guest

    Many thanks, Mark. It works OK.

    Ericsson.

    "Mark Warren" <> a écrit dans le message de
    news:bflhdt$g06kt$-berlin.de...
    > "Ericcson" <> wrote in message
    > news:bflh4j$qdb$...
    > > Hi.
    > > ----------------------------------------
    > > #include <fstream>
    > > #include <stdlib.h>
    > > #include <sstream>
    > > #include <iostream>
    > >
    > > using namespace std ;
    > > int main() {
    > > ostringstream myO;
    > > myO << 12;
    > > cout << "myO = " << myO.str() <<endl;
    > > myO << 8;
    > > cout << "myO =" << myO.str() <<endl;
    > > return 0;
    > > }
    > > --------------
    > >
    > > I get :
    > > 12
    > > 128
    > >
    > > I would like to get :
    > > 12
    > > 8
    > > i.e to clear the myO buffer before filling it with "8".
    > > I don't find how. Could someone help me ?
    > >
    > > TIA
    > > Ericsson
    > >
    > > PS : the all strory is that I try to convert an integer to a string . I
    > > tried itoa(12,s,10) and sprintf(s,"%d",12) with or without c_str() and

    > only
    > > got compilation errors.
    > >

    >
    > Use myO.str(""). A non-obvious use and IMHO poor design, a function

    should
    > only have one use.
    >
    > Mark
    >
    >
     
    Ericcson, Jul 23, 2003
    #2
    1. Advertising

  3. Mark Warren

    tom_usenet Guest

    On Wed, 23 Jul 2003 09:35:15 +0100, "Mark Warren"
    <> wrote:
    >Use myO.str(""). A non-obvious use and IMHO poor design, a function should
    >only have one use.


    That function does only have one use (to set the string held by the
    ss). Or are you against overloading?

    Tom
     
    tom_usenet, Jul 23, 2003
    #3
  4. Mark Warren

    Sam Holden Guest

    On Wed, 23 Jul 2003 09:25:26 GMT, tom_usenet <> wrote:
    > On Wed, 23 Jul 2003 09:35:15 +0100, "Mark Warren"
    ><> wrote:
    >>Use myO.str(""). A non-obvious use and IMHO poor design, a function should
    >>only have one use.

    >
    > That function does only have one use (to set the string held by the
    > ss). Or are you against overloading?


    It also returns the current string (an example of such usage was in the
    OP...).

    Hence one function, two uses.

    Overloading a function name is fine, but the functions should do the
    similar actions.

    --
    Sam Holden
     
    Sam Holden, Jul 23, 2003
    #4
    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. Emmanuel Freund

    clear the java buffer

    Emmanuel Freund, Nov 24, 2004, in forum: Java
    Replies:
    5
    Views:
    861
    Emmanuel Freund
    Nov 24, 2004
  2. Kyle Kolander

    ostringstream clear

    Kyle Kolander, Jul 3, 2005, in forum: C++
    Replies:
    3
    Views:
    677
    Steven T. Hatton
    Jul 5, 2005
  3. David

    Response.Clear() doesn't clear

    David, Jan 31, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    1,093
    Mark Fitzpatrick
    Jan 31, 2008
  4. wang

    "clear" an ostringstream

    wang, Aug 14, 2010, in forum: C++
    Replies:
    12
    Views:
    1,106
  5. InvalidLastName

    Unrecognized element 'add' after <clear></clear>

    InvalidLastName, Feb 26, 2007, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    1,039
    Steven Cheng[MSFT]
    Mar 6, 2007
Loading...

Share This Page