C++ crew.. simple question

Discussion in 'OT Technology' started by C5Load, Feb 10, 2006.

  1. C5Load

    C5Load OT Resident UCLA fanatic

    Joined:
    Nov 27, 2001
    Messages:
    11,562
    Likes Received:
    0
    Location:
    Wherever Freddie takes me
    i've got one of those teachers that reads the powerpoint presentations, which are straight from the book (god damn guy has his doctorate, for god's sakes... figure he could teach some)

    we're going over the basic cin variations today (yes, early in the semester), and I'm having some issues.

    I understand get, setw, and all that other good stuff, but i'll be damned if i can understand what peek is for. I understand that it reads the next character without extracting it, but why the hell would you need to?

    someone able to explain?
     
  2. dtfromep

    dtfromep New Member

    Joined:
    Oct 11, 2003
    Messages:
    1,674
    Likes Received:
    0
    Location:
    Saint Paul, MN
    Pretty sure that looks at the next character without advancing the 'current position' pointer. It has been a while since cin days though.
     
  3. lazyjk

    lazyjk Uncle Sam wants you for the NEW Freedom Fighters!!

    Joined:
    Sep 26, 2005
    Messages:
    5,168
    Likes Received:
    0
    Location:
    Lewistown, Mt
    I had to use peek in some assignments where I had to read in characters from a file, and by using peek, you can avoid reading in characters that you don't want :dunno:

    I haven't used it except for those assignments since though.
     
  4. ChosenGSR

    ChosenGSR Mama always said you'd be the chosen one

    Joined:
    Oct 24, 2001
    Messages:
    51,097
    Likes Received:
    240
    Location:
    HoCo, MD
    example something along the lines of VB syntax

    you're looping through the file and reading line by line. using the peek function you can look ahead and see if there is another line in the file.

    while file.peek > 0
    line = file.readline


    end while
     
  5. C5Load

    C5Load OT Resident UCLA fanatic

    Joined:
    Nov 27, 2001
    Messages:
    11,562
    Likes Received:
    0
    Location:
    Wherever Freddie takes me
    but what's the point? :dunno:
     
  6. ChosenGSR

    ChosenGSR Mama always said you'd be the chosen one

    Joined:
    Oct 24, 2001
    Messages:
    51,097
    Likes Received:
    240
    Location:
    HoCo, MD
    have you even looked at my example?

    without doing the peek it would actually be much harder to write that same piece of code.
     
  7. antiyou

    antiyou OT Supporter

    Joined:
    Jul 13, 2005
    Messages:
    25,295
    Likes Received:
    0
    Location:
    in ur base
    when parsing a file you can check for a specific character and then take appropriate action.
     

Share This Page