stringstream

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

    stringstream

    is there an easy way to clear a stringstreams contents.
    My problem is that I want output to be limited to 80 characters
    a line. So I use operator<< to a stringstream object 'oss' and
    if tellp() is > 80, I use operator<< to output
    oss.rdbuf()->str();
    Afterwards I want to clear oss contents. Is there a way.
    pubseekpos(0) seems not to delete the former contents.
    Is there maybe a more elegant way to archieve what I want?
    I find 'oss.rdbuf()->str()' already to complicated.

    cout << oss; oss.clear();

    would look much nicer.

    thanks,
    marc

  • Sean

    #2
    Re: stringstream


    "Marc Schellens" <m_schellens@ho tmail.com> wrote in message
    news:3F00F1FA.4 000708@hotmail. com...[color=blue]
    > is there an easy way to clear a stringstreams contents.
    > My problem is that I want output to be limited to 80 characters
    > a line. So I use operator<< to a stringstream object 'oss' and
    > if tellp() is > 80, I use operator<< to output
    > oss.rdbuf()->str();
    > Afterwards I want to clear oss contents. Is there a way.
    > pubseekpos(0) seems not to delete the former contents.
    > Is there maybe a more elegant way to archieve what I want?
    > I find 'oss.rdbuf()->str()' already to complicated.
    >
    > cout << oss; oss.clear();
    >
    > would look much nicer.
    >
    > thanks,
    > marc
    >[/color]

    cout << oss.str() ; oss.str("")

    Cheers,
    Sean


    Comment

    • Marc Schellens

      #3
      Re: stringstream

      Thanks,
      thats exactly what I wanted to know.
      But as we are on it:
      How can I check if there is already an 'endl' inserted in an
      ostringstream ?
      My tries with pubseekpos(...) weren't successful so far...
      Do I need a stringstream then?

      thanks,
      marc

      Sean wrote:[color=blue]
      > "Marc Schellens" <m_schellens@ho tmail.com> wrote in message
      > news:3F00F1FA.4 000708@hotmail. com...
      >[color=green]
      >>is there an easy way to clear a stringstreams contents.
      >>My problem is that I want output to be limited to 80 characters
      >>a line. So I use operator<< to a stringstream object 'oss' and
      >>if tellp() is > 80, I use operator<< to output
      >>oss.rdbuf()->str();
      >>Afterwards I want to clear oss contents. Is there a way.
      >>pubseekpos( 0) seems not to delete the former contents.
      >>Is there maybe a more elegant way to archieve what I want?
      >>I find 'oss.rdbuf()->str()' already to complicated.
      >>
      >>cout << oss; oss.clear();
      >>
      >>would look much nicer.
      >>
      >>thanks,
      >>marc
      >>[/color]
      >
      >
      > cout << oss.str() ; oss.str("")
      >
      > Cheers,
      > Sean
      >
      >[/color]

      Comment

      • Sean

        #4
        Re: stringstream


        "Marc Schellens" <m_schellens@ho tmail.com> wrote in message
        news:3F012A94.3 000306@hotmail. com...[color=blue]
        > Thanks,
        > thats exactly what I wanted to know.
        > But as we are on it:
        > How can I check if there is already an 'endl' inserted in an
        > ostringstream ?
        > My tries with pubseekpos(...) weren't successful so far...
        > Do I need a stringstream then?
        >
        > thanks,
        > marc
        >[/color]

        Marc,

        Not really sure what you are looking for but
        perhaps this will help :

        string ms(oss.str());
        int elp = ms.find("\n");
        if (elp == string::npos)
        cout << ms; // no endl found
        else cout << ms.substr(0,elp ); // endl found, show substring

        HTH,
        Sean





        Comment

        Working...