[iostream] how to get the rest string of a istream

Discussion in 'C++' started by mos, Jun 24, 2006.

  1. mos

    mos Guest

    Hi!

    the question can describle as code:

    //os like "mike head hello world!"
    string GetRest(istringstream& os)
    {
    string name,part; //and maybe some other element
    os >> name >> part;
    //do something...

    ostringstream stream2;
    stream2 << stream.rdbuf();
    return stream2.str()
    }

    I just want the rest of os ("hello world!"), but my method seems ugly, is
    there a graceful way?

    thanks in advance.

    jiang.yu
     
    mos, Jun 24, 2006
    #1
    1. Advertising

  2. mos

    benben Guest

    mos wrote:
    > Hi!
    >
    > the question can describle as code:
    >
    > //os like "mike head hello world!"
    > string GetRest(istringstream& os)
    > {
    > string name,part; //and maybe some other element
    > os >> name >> part;
    > //do something...
    >
    > ostringstream stream2;
    > stream2 << stream.rdbuf();
    > return stream2.str()
    > }
    >
    > I just want the rest of os ("hello world!"), but my method seems ugly, is
    > there a graceful way?


    Take a string as input, search for the second blank space, and retrieve
    the substring.

    Ben

    >
    > thanks in advance.
    >
    > jiang.yu
    >
    >
    >
     
    benben, Jun 24, 2006
    #2
    1. Advertising

  3. mos

    mos Guest

    Hi!
    Your answer not satisfy me.
    How do I know it is the second black space, may be '\t', may be '\n'
    And I want to general way to get the rest of a istream.

    jiang.yu

    "benben" <>
    ??????:449d270d$0$14512$...
    > mos wrote:
    >> Hi!
    >>
    >> the question can describle as code:
    >>
    >> //os like "mike head hello world!"
    >> string GetRest(istringstream& os)
    >> {
    >> string name,part; //and maybe some other element
    >> os >> name >> part;
    >> //do something...
    >>
    >> ostringstream stream2;
    >> stream2 << stream.rdbuf();
    >> return stream2.str()
    >> }
    >>
    >> I just want the rest of os ("hello world!"), but my method seems ugly,
    >> is there a graceful way?

    >
    > Take a string as input, search for the second blank space, and retrieve
    > the substring.
    >
    > Ben
    >
    >>
    >> thanks in advance.
    >>
    >> jiang.yu
    >>
    >>
     
    mos, Jun 26, 2006
    #3
  4. mos

    Jim Langston Guest

    "mos" <> wrote in message
    news:e7nkc9$1tb$99.com...
    > Hi!
    > Your answer not satisfy me.
    > How do I know it is the second black space, may be '\t', may be '\n'
    > And I want to general way to get the rest of a istream.
    >
    > jiang.yu
    >
    > "benben" <>
    > ??????:449d270d$0$14512$...
    >> mos wrote:
    >>> Hi!
    >>>
    >>> the question can describle as code:
    >>>
    >>> //os like "mike head hello world!"
    >>> string GetRest(istringstream& os)
    >>> {
    >>> string name,part; //and maybe some other element
    >>> os >> name >> part;
    >>> //do something...
    >>>
    >>> ostringstream stream2;
    >>> stream2 << stream.rdbuf();
    >>> return stream2.str()
    >>> }


    You could just return istringstream& and let whatever calls it get them
    itself.

    >>> I just want the rest of os ("hello world!"), but my method seems ugly,
    >>> is there a graceful way?

    >>
    >> Take a string as input, search for the second blank space, and retrieve
    >> the substring.
    >>
    >> Ben
    >>
    >>>
    >>> thanks in advance.
    >>>
    >>> jiang.yu
    >>>
    >>>

    >
     
    Jim Langston, Jun 26, 2006
    #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. John Tiger
    Replies:
    10
    Views:
    5,632
  2. ai@work
    Replies:
    9
    Views:
    556
    Ron Natalie
    Dec 16, 2004
  3. Johannes Zellner

    extracting rest of an istream (istrstream)

    Johannes Zellner, Jan 20, 2006, in forum: C++
    Replies:
    4
    Views:
    428
    Mike Wahler
    Jan 20, 2006
  4. arnuld
    Replies:
    1
    Views:
    351
    =?ISO-8859-1?Q?Erik_Wikstr=F6m?=
    Aug 21, 2007
  5. xmllmx
    Replies:
    5
    Views:
    597
    Jorgen Grahn
    Jun 15, 2010
Loading...

Share This Page