By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,107 Members | 1,173 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,107 IT Pros & Developers. It's quick & easy.

A Question about getline

P: n/a
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?

Jul 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
JustSomeGuy wrote:
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.

--
Salu2
Jul 22 '05 #2

P: n/a

"JustSomeGuy" <no**@nottelling.com> wrote in message
news:T5D5d.115773$%S.55430@pd7tw2no...
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
Jul 22 '05 #3

P: n/a

"John Harrison" <jo*************@hotmail.com> wrote in message
news:2r*************@uni-berlin.de...

"JustSomeGuy" <no**@nottelling.com> wrote in message
news:T5D5d.115773$%S.55430@pd7tw2no...
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.

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?
john


Jul 22 '05 #4

P: n/a

"JustSomeGuy" <no**@nottelling.com> wrote in message
news:vGE5d.539077$gE.434615@pd7tw3no...

"John Harrison" <jo*************@hotmail.com> wrote in message
news:2r*************@uni-berlin.de...

"JustSomeGuy" <no**@nottelling.com> wrote in message
news:T5D5d.115773$%S.55430@pd7tw2no...
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.

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
Jul 22 '05 #5

P: n/a
On Sun, 26 Sep 2004 19:23:07 GMT in comp.lang.c++, "JustSomeGuy"
<no**@nottelling.com> wrote,
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/gr*********....earthlink.net

What are you trying to accomplish?

Jul 22 '05 #6

P: n/a

"JustSomeGuy" <no**@nottelling.com> wrote in message
news:vGE5d.539077$gE.434615@pd7tw3no...

"John Harrison" <jo*************@hotmail.com> wrote in message
news:2r*************@uni-berlin.de...

"JustSomeGuy" <no**@nottelling.com> wrote in message
news:T5D5d.115773$%S.55430@pd7tw2no...
> 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.

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
Jul 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.