Thread: getline with a dual delimiter?

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    45

    getline with a dual delimiter?

    How would I make the this
    Code:
    inFile.getline(temp, 10, ' ');
    stop at both a ' ' and a newline. Right now it is reading in a file and when it hits the end of a line without a space it will read in that last value and the first value of the next line. How do I tell it to be more specific than just the space?

  2. #2
    UCF Mystic_Skies's Avatar
    Join Date
    Oct 2004
    Posts
    33
    This website might have some help on what you're looking for. Number 9 I believe: http://www.augustcouncil.com/~tgibso...al/iotips.html

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    45
    I read the site, and already understood that part of it.
    Let me give you an example of what my problem is...
    I am using
    Code:
            inFile.getline(temp, 10, ' ');
    to scan in a list like this...

    92 64 85 100 74 64 99 74 94 88
    100 66 82 74 93 88 66 85 99 72

    In the process of debuggin this problem I printed out a list of the values that were scaned in...
    #0 92
    #1 64
    #2 85
    #3 100
    #4 74
    #5 64
    #6 99
    #7 74
    #8 94
    #9 88
    100
    #10 66
    #11 82
    ...
    It sees 100 as if it was in the #9 position with 88... It does with with every newline from my data files.... How can I either pull the 100 out of that string and split the two numbers into their own strings or how do I make sure that I will pick up the new line next time...

  4. #4
    Registered User Kybo_Ren's Avatar
    Join Date
    Sep 2004
    Posts
    136
    Read each line (getline with a '\n') into a string, then use getline with ' ' on a stringstream.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Or use a normal operator >> for ints, it will break at all kinds of whitespace.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  2. buying a laptop ; intel dual core?
    By BobMcGee123 in forum A Brief History of Cprogramming.com
    Replies: 27
    Last Post: 07-30-2006, 02:28 PM
  3. getline help
    By ProjectsProject in forum C++ Programming
    Replies: 3
    Last Post: 06-14-2004, 11:12 AM
  4. Windows Dual Boot
    By netboy in forum Tech Board
    Replies: 33
    Last Post: 09-15-2003, 11:26 AM
  5. getline with string class in Borland C++
    By johnnyd in forum C++ Programming
    Replies: 6
    Last Post: 03-08-2003, 02:59 PM