stringstream

Discussion in 'C++' started by Marc Schellens, Jul 1, 2003.

  1. 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
     
    Marc Schellens, Jul 1, 2003
    #1
    1. Advertising

  2. 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:
    > "Marc Schellens" <> wrote in message
    > news:...
    >
    >>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
    >>

    >
    >
    > cout << oss.str() ; oss.str("")
    >
    > Cheers,
    > Sean
    >
    >
     
    Marc Schellens, Jul 1, 2003
    #2
    1. Advertising

  3. Marc Schellens

    Sean Guest

    "Marc Schellens" <> wrote in message
    news:...
    > 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
    >


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

    Cheers,
    Sean
     
    Sean, Jul 1, 2003
    #3
  4. Marc Schellens

    Sean Guest

    "Marc Schellens" <> wrote in message
    news:...
    > 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
    >


    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
     
    Sean, Jul 1, 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. minjie
    Replies:
    1
    Views:
    691
    Victor Bazarov
    Jul 15, 2003
  2. Bill Beacom

    stringstream problem

    Bill Beacom, Sep 15, 2003, in forum: C++
    Replies:
    2
    Views:
    477
    Peter Kragh
    Sep 15, 2003
  3. Ellarco
    Replies:
    5
    Views:
    4,618
    Ellarco
    Sep 24, 2003
  4. Medi Montaseri

    How to shrink a stringstream

    Medi Montaseri, Sep 25, 2003, in forum: C++
    Replies:
    2
    Views:
    394
    Medi Montaseri
    Sep 26, 2003
  5. mark lawler
    Replies:
    0
    Views:
    402
    mark lawler
    Oct 17, 2003
Loading...

Share This Page