Newline in a File Text file

Discussion in 'C++' started by utab, Mar 10, 2006.

  1. utab

    utab Guest

    Dear all,

    I have a text file in the form of

    1 2 3 4 5 6
    --------/--------/--------/--------/--------/--------/ (I just used /
    to better explain the fields)

    6 fields of 8 characters. I want to read lets say fields 4,5 and 6 and
    then go to the begining of the newline which is in the same format. And
    then I will test the first character of the newline with $ and if true
    the read process will terminate. I can read fields by positioning the
    file pointer with seekg() function. Is there a direct way to position
    the file pointer to the start of a newline.

    I tried things but all gone wrong, I could not solve the problem of
    going to the start of the newline.

    Any help is appreciated.

    Thanks.
    utab, Mar 10, 2006
    #1
    1. Advertising

  2. utab wrote:
    > I tried things but all gone wrong, I could not solve the problem of
    > going to the start of the newline.


    I'm not exactly clear what you want to do. Apparently you want to
    skip all characters at some point until the start of the next line.
    The easiest way to do just this is to use the 'ignore()' member of
    'std::istream':

    in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

    This will skip all characters up to and including the next newline
    character.
    --
    <mailto:> <http://www.dietmar-kuehl.de/>
    <http://www.eai-systems.com> - Efficient Artificial Intelligence
    Dietmar Kuehl, Mar 10, 2006
    #2
    1. Advertising

  3. utab

    utab Guest

    Thanks first,

    lets say I read field 3 and then I would like to go to the start of the
    newline immediately. I think it is more clear now.
    But I guess this is quite OK with what I would like to do.

    Thanks.
    utab, Mar 10, 2006
    #3
  4. utab wrote:
    > lets say I read field 3 and then I would like to go to the start of the
    > newline immediately. I think it is more clear now.


    Is it...? Well, then...

    Using 'ignore()' as shown in my previous reply, you can skip all
    characters and go the next newline. There is no way to kind of
    "jump" there without having the library look at the characters
    because the file does not have any knowledge about the structure
    within. You might have some success with fixed record size when
    using the "C" locale, i.e. when the characters are not encoded,
    but I would personally rather have 'ignore()' for the next line
    start.
    --
    <mailto:> <http://www.dietmar-kuehl.de/>
    <http://www.eai-systems.com> - Efficient Artificial Intelligence
    Dietmar Kuehl, Mar 10, 2006
    #4
    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. Matt
    Replies:
    2
    Views:
    1,109
    Joris Gillis
    Nov 2, 2004
  2. bmgz
    Replies:
    5
    Views:
    650
    Alex Martelli
    Dec 25, 2003
  3. elsa
    Replies:
    6
    Views:
    998
    alex23
    Aug 4, 2010
  4. TTT

    Display text with <newline> characters...

    TTT, Jun 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    111
    Nathan Sokalski
    Jun 23, 2006
  5. Krzysztof Fink-Finowicki via .NET 247

    Unicode and newline characters in XML text sond via Web Service

    Krzysztof Fink-Finowicki via .NET 247, Oct 17, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    131
    Krzysztof Fink-Finowicki via .NET 247
    Oct 17, 2004
Loading...

Share This Page