A Question about getline

Discussion in 'C++' started by JustSomeGuy, Sep 26, 2004.

  1. JustSomeGuy

    JustSomeGuy Guest

    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?
     
    JustSomeGuy, Sep 26, 2004
    #1
    1. Advertising

  2. 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
     
    =?ISO-8859-15?Q?Juli=E1n?= Albo, Sep 26, 2004
    #2
    1. Advertising

  3. "JustSomeGuy" <> 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
     
    John Harrison, Sep 26, 2004
    #3
  4. JustSomeGuy

    JustSomeGuy Guest

    "John Harrison" <> wrote in message
    news:...
    >
    > "JustSomeGuy" <> 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
    >
    >
     
    JustSomeGuy, Sep 26, 2004
    #4
  5. JustSomeGuy

    Mike Wahler Guest

    "JustSomeGuy" <> wrote in message
    news:vGE5d.539077$gE.434615@pd7tw3no...
    >
    > "John Harrison" <> wrote in message
    > news:...
    > >
    > > "JustSomeGuy" <> 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
     
    Mike Wahler, Sep 27, 2004
    #5
  6. JustSomeGuy

    David Harmon Guest

    On Sun, 26 Sep 2004 19:23:07 GMT in comp.lang.c++, "JustSomeGuy"
    <> 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/groups?selm=

    What are you trying to accomplish?
     
    David Harmon, Sep 27, 2004
    #6
  7. "JustSomeGuy" <> wrote in message
    news:vGE5d.539077$gE.434615@pd7tw3no...
    >
    > "John Harrison" <> wrote in message
    > news:...
    >>
    >> "JustSomeGuy" <> 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
     
    John Harrison, Sep 27, 2004
    #7
    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
    Replies:
    10
    Views:
    10,075
    Buster Copley
    Jul 14, 2003
  2. Poof
    Replies:
    1
    Views:
    396
  3. Victor Bazarov

    Re: istream::getline

    Victor Bazarov, Aug 13, 2003, in forum: C++
    Replies:
    0
    Views:
    2,150
    Victor Bazarov
    Aug 13, 2003
  4. Skywise
    Replies:
    11
    Views:
    4,691
  5. Amadeus W. M.

    getline and EOF question

    Amadeus W. M., Jul 1, 2005, in forum: C++
    Replies:
    18
    Views:
    946
    Amadeus W. M.
    Jul 7, 2005
Loading...

Share This Page