problem with getline

Discussion in 'C++' started by ankit.kumar.agarwal@gmail.com, Mar 10, 2007.

  1. Guest

    I am facing a problem with getline
    I am reading a text file with a getline function the lines can have
    '|' as separator.

    everything works OK but in case if i have 2 delimitors in file '234||
    dfdg' so here
    my program does not go beyond the 2nd '|'.
    i am using ifstream to read the file.
    somehow check for eof() gets passed although end of file is not there.
    i am using
    mFile->getline(mBuf,Length, Delimiter);



    please help me.
    , Mar 10, 2007
    #1
    1. Advertising

  2. wrote:
    > I am facing a problem with getline
    > I am reading a text file with a getline function the lines can have
    > '|' as separator.
    >
    > everything works OK but in case if i have 2 delimitors in file '234||
    > dfdg' so here
    > my program does not go beyond the 2nd '|'.
    > i am using ifstream to read the file.
    > somehow check for eof() gets passed although end of file is not there.
    > i am using
    > mFile->getline(mBuf,Length, Delimiter);
    >
    >
    >
    > please help me.
    >


    Misunderstanding how getline, operator>> and end of file works is one of
    the commonest errors we see on this group. But we cannot help you unless
    you post the code that doesn't work. We are not psychic.

    john
    John Harrison, Mar 10, 2007
    #2
    1. Advertising

  3. Guest

    On Mar 10, 1:49 am, John Harrison <> wrote:
    > wrote:
    > > I am facing a problem with getline
    > > I am reading a text file with a getline function the lines can have
    > > '|' as separator.

    >
    > > everything works OK but in case if i have 2 delimitors in file '234||
    > > dfdg' so here
    > > my program does not go beyond the 2nd '|'.
    > > i am using ifstream to read the file.
    > > somehow check for eof() gets passed although end of file is not there.
    > > i am using
    > > mFile->getline(mBuf,Length, Delimiter);

    >
    > > please help me.

    >
    > Misunderstanding how getline, operator>> and end of file works is one of
    > the commonest errors we see on this group. But we cannot help you unless
    > you post the code that doesn't work. We are not psychic.
    >
    > john- Hide quoted text -
    >
    > - Show quoted text -


    Can you please tell me that how getline behaves when it sees 2
    delimiters sid by side , can it cause
    eof() to become true , is it normal
    and is their any solution to this
    , Mar 10, 2007
    #3
  4. wrote:
    > On Mar 10, 1:49 am, John Harrison <> wrote:
    >
    >> wrote:
    >>
    >>>I am facing a problem with getline
    >>>I am reading a text file with a getline function the lines can have
    >>>'|' as separator.

    >>
    >>>everything works OK but in case if i have 2 delimitors in file '234||
    >>>dfdg' so here
    >>>my program does not go beyond the 2nd '|'.
    >>>i am using ifstream to read the file.
    >>>somehow check for eof() gets passed although end of file is not there.
    >>>i am using
    >>>mFile->getline(mBuf,Length, Delimiter);

    >>
    >>>please help me.

    >>
    >>Misunderstanding how getline, operator>> and end of file works is one of
    >>the commonest errors we see on this group. But we cannot help you unless
    >>you post the code that doesn't work. We are not psychic.
    >>
    >>john- Hide quoted text -
    >>
    >>- Show quoted text -

    >
    >
    > Can you please tell me that how getline behaves when it sees 2
    > delimiters sid by side , can it cause
    > eof() to become true , is it normal
    > and is their any solution to this
    >


    Each delimiter is the end of a different line.

    getline cause eof to become true when it reads past the end of a file.

    If you cannot post the code, then we cannot help you. The mistake you
    are making is different from what you think it is. Post the code so me
    or someone else can tell you what the mistake you are making is.

    john
    John Harrison, Mar 10, 2007
    #4
  5. Guest

    On Mar 10, 11:59 am, John Harrison <>
    wrote:
    > wrote:
    > > On Mar 10, 1:49 am, John Harrison <> wrote:

    >
    > >> wrote:

    >
    > >>>I am facing a problem with getline
    > >>>I am reading a text file with a getline function the lines can have
    > >>>'|' as separator.

    >
    > >>>everything works OK but in case if i have 2 delimitors in file '234||
    > >>>dfdg' so here
    > >>>my program does not go beyond the 2nd '|'.
    > >>>i am using ifstream to read the file.
    > >>>somehow check for eof() gets passed although end of file is not there.
    > >>>i am using
    > >>>mFile->getline(mBuf,Length, Delimiter);

    >
    > >>>please help me.

    >
    > >>Misunderstanding how getline, operator>> and end of file works is one of
    > >>the commonest errors we see on this group. But we cannot help you unless
    > >>you post the code that doesn't work. We are not psychic.

    >
    > >>john- Hide quoted text -

    >
    > >>- Show quoted text -

    >
    > > Can you please tell me that how getline behaves when it sees 2
    > > delimiters sid by side , can it cause
    > > eof() to become true , is it normal
    > > and is their any solution to this

    >
    > Each delimiter is the end of a different line.
    >
    > getline cause eof to become true when it reads past the end of a file.
    >
    > If you cannot post the code, then we cannot help you. The mistake you
    > are making is different from what you think it is. Post the code so me
    > or someone else can tell you what the mistake you are making is.
    >
    > john- Hide quoted text -
    >
    > - Show quoted text -

    will getline set some error bit if it could not read any character
    bacause it found a deleimiter
    as the first character.

    Please suggest How to post a code of 1000+ lines having dependencies
    on multiple files
    , Mar 11, 2007
    #5
  6. wrote:
    > On Mar 10, 11:59 am, John Harrison <>
    > wrote:
    >
    >> wrote:
    >>
    >>>On Mar 10, 1:49 am, John Harrison <> wrote:

    >>
    >>>> wrote:

    >>
    >>>>>I am facing a problem with getline
    >>>>>I am reading a text file with a getline function the lines can have
    >>>>>'|' as separator.

    >>
    >>>>>everything works OK but in case if i have 2 delimitors in file '234||
    >>>>>dfdg' so here
    >>>>>my program does not go beyond the 2nd '|'.
    >>>>>i am using ifstream to read the file.
    >>>>>somehow check for eof() gets passed although end of file is not there.
    >>>>>i am using
    >>>>>mFile->getline(mBuf,Length, Delimiter);

    >>
    >>>>>please help me.

    >>
    >>>>Misunderstanding how getline, operator>> and end of file works is one of
    >>>>the commonest errors we see on this group. But we cannot help you unless
    >>>>you post the code that doesn't work. We are not psychic.

    >>
    >>>>john- Hide quoted text -

    >>
    >>>>- Show quoted text -

    >>
    >>>Can you please tell me that how getline behaves when it sees 2
    >>>delimiters sid by side , can it cause
    >>>eof() to become true , is it normal
    >>>and is their any solution to this

    >>
    >>Each delimiter is the end of a different line.
    >>
    >>getline cause eof to become true when it reads past the end of a file.
    >>
    >>If you cannot post the code, then we cannot help you. The mistake you
    >>are making is different from what you think it is. Post the code so me
    >>or someone else can tell you what the mistake you are making is.
    >>
    >>john- Hide quoted text -
    >>
    >>- Show quoted text -

    >
    > will getline set some error bit if it could not read any character
    > bacause it found a deleimiter
    > as the first character.


    No.

    >
    > Please suggest How to post a code of 1000+ lines having dependencies
    > on multiple files
    >


    Remove the parts that aren't working and post those. It helps if you
    post a complete program but if that's not possible then posting some
    code will give someone some chance of spotting an error.

    john
    John Harrison, Mar 11, 2007
    #6
  7. Gavin Deane Guest

    Gavin Deane, Mar 11, 2007
    #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,050
    Buster Copley
    Jul 14, 2003
  2. Poof
    Replies:
    1
    Views:
    382
  3. Joe
    Replies:
    4
    Views:
    7,751
    Chris Theis
    Jan 22, 2004
  4. solartimba

    getline problem

    solartimba, Apr 6, 2004, in forum: C++
    Replies:
    1
    Views:
    430
    Leor Zolman
    Apr 6, 2004
  5. Alex

    getline problem

    Alex, Jun 5, 2004, in forum: C++
    Replies:
    6
    Views:
    509
    Victor Bazarov
    Jun 6, 2004
Loading...

Share This Page