Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > [iostream] how to get the rest string of a istream

Reply
Thread Tools

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

 
 
mos
Guest
Posts: n/a
 
      06-24-2006
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



 
Reply With Quote
 
 
 
 
benben
Guest
Posts: n/a
 
      06-24-2006
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
>
>
>

 
Reply With Quote
 
 
 
 
mos
Guest
Posts: n/a
 
      06-26-2006
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" <(E-Mail Removed)>
??????:449d270d$0$14512$(E-Mail Removed) .au...
> 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
>>
>>


 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      06-26-2006
"mos" <(E-Mail Removed)> wrote in message
news:e7nkc9$1tb$(E-Mail Removed)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" <(E-Mail Removed)>
> ??????:449d270d$0$14512$(E-Mail Removed) .au...
>> 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
>>>
>>>

>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Does the C++ standard define the global function of " istream&operator >>(istream& in, string& str); "? xmllmx C++ 5 06-15-2010 11:57 AM
extracting rest of an istream (istrstream) Johannes Zellner C++ 4 01-20-2006 06:39 PM
from std::string to std::istream? Gernot Frisch C++ 4 03-18-2005 02:26 PM
istream >> (my own string class) - low-level solution? matthurne C++ 3 07-22-2004 02:37 PM



Advertisments