A Question about getline

J

JustSomeGuy

Getline has a delimiter character parameter that is used to say when input
should stop. (std::cin.getline)

However what do you do if you have multiple conditions/character on which
you wish to stop line input?
 
?

=?ISO-8859-15?Q?Juli=E1n?= Albo

JustSomeGuy said:
Getline has a delimiter character parameter that is used to say when input
should stop. (std::cin.getline)
However what do you do if you have multiple conditions/character on which
you wish to stop line input?

You write a function that do what you need.
 
J

John Harrison

JustSomeGuy said:
Getline has a delimiter character parameter that is used to say when input
should stop. (std::cin.getline)

However what do you do if you have multiple conditions/character on which
you wish to stop line input?

Write a function. For instance you can read one character at a time until
you hit one of you multiple conditions/characters.

john
 
J

JustSomeGuy

John Harrison said:
Write a function. For instance you can read one character at a time until
you hit one of you multiple conditions/characters.
Ya thats kinda what I thought to.. but was just trying to see if there
was something I was missing.. Know what I mean?

Do you recommend that I write my own class and extent on basic_istream?
 
M

Mike Wahler

JustSomeGuy said:
Ya thats kinda what I thought to.. but was just trying to see if there
was something I was missing.. Know what I mean?

Do you recommend that I write my own class and extent on basic_istream?

No need. Just write a function. One possible method would be:

Use 'getline()' with some 'default' delimiter character (use one
from the set of delimiters you want to use).

Apply 'std::find_first_of()' to the string written by 'getline()'.

-Mike
 
D

David Harmon

On Sun, 26 Sep 2004 19:23:07 GMT in comp.lang.c++, "JustSomeGuy"
Do you recommend that I write my own class and extent on basic_istream?

Heck no.

I might recommend that you write a more elaborate substitute for
std::getline(std::istream &, std::string &, etc.) like has already been
suggested.

I might recommend you call std::getline and then subject the line of
input to further machinations like in
http://groups.google.com/[email protected]

What are you trying to accomplish?
 
J

John Harrison

JustSomeGuy said:
Ya thats kinda what I thought to.. but was just trying to see if there
was something I was missing.. Know what I mean?

Do you recommend that I write my own class and extent on basic_istream?

No, not at all, why would you do that? Just write a function.

Suppose you want to read upto the next comma or newline

std::string my_getline(std::istream& in)
{
char ch;
std::string res;
while (in.get(ch) && ch != ',' && ch != '\n')
res += ch;
return res;
}

Untested code.

john
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top