Thread: getline()

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

    getline()

    Can someone explain the purpose of this function?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Can someone explain the purpose of this function?
    I would think the purpose to be pretty straight forward, it gets a line from input.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    getline() will store inputs from the stream until '\n'.

    Kuphryn

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    the insertion operator >> is used to input data into a variable from the input buffer. It ignores leading whitespace, inputs nonwhite space data into the variable, and then stops input at the next whitespace data, but doesn't remove the terminating whitespace data from the input buffer. If the input is into a char buffer it automatically adds the terminating null char to the end of the valid input.

    getline() doesn't ignore leading whitespace. It inputs all material in the input buffer into a string buffer up to a given number of char inputs or until a terminating char is identified. The terminating char defaults to the new line char. The terminating char, if found, is removed from the buffer. The null char is automatically added to the end of the string buffer input. getline() has two main variants:

    //to be used with C style strings
    istreamName.getline(bufferName, MaxNumCharToRead, 'terminatingChar');

    //to be used with STL strings
    getline(istreamName, STLstringName, 'terminatingChar');

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. getline problem
    By Bitphire in forum C++ Programming
    Replies: 5
    Last Post: 10-18-2004, 04:42 PM
  3. getline help
    By ProjectsProject in forum C++ Programming
    Replies: 3
    Last Post: 06-14-2004, 11:12 AM
  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