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

M

mos

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
 
B

benben

mos said:
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
 
M

mos

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
 
J

Jim Langston

mos said:
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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top