get() vs getline()

This is a discussion on get() vs getline() within the C++ Programming forums, part of the General Programming Boards category; Can someone please explain this. Thanks in advance!...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    51

    get() vs getline()

    Can someone please explain this.

    Thanks in advance!

  2. #2
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    get() retrieves a single character

    getline() retrieves multiple characters (as many as it takes to get to the number you specify or until the delimiter ['\n' by default] is read). note that the delimiting character is not inserted into the buffer.
    Last edited by LuckY; 04-28-2003 at 06:00 PM.

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    51
    Then is
    Code:
    fin >> cChar;
    equivalent to
    Code:
    fin.get(cChar)
    Thanks in advance.

  4. #4
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    No.
    The difference between operator>>() and get() is that operator>>() ignores whitespace.

    So if the source data was "a b c" and you did fin >> ch 3 times, you would have extracted 'a' 'b' and 'c'
    However if you did fin.get() three times, you would have extracted 'a' ' ' and 'b'

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    51
    Wow, that helps alot. Thanks!!!

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, 11:50 AM
  2. getline problem
    By Bitphire in forum C++ Programming
    Replies: 5
    Last Post: 10-18-2004, 05:42 PM
  3. getline help
    By ProjectsProject in forum C++ Programming
    Replies: 3
    Last Post: 06-14-2004, 12:12 PM
  4. getline not working right
    By talz13 in forum C++ Programming
    Replies: 11
    Last Post: 12-10-2003, 11:46 PM
  5. getline with string class in Borland C++
    By johnnyd in forum C++ Programming
    Replies: 6
    Last Post: 03-08-2003, 02:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21