What is the difference between get and getline ?

Showing Answers 1 - 7 of 7 Answers

mysteriousgal

  • Mar 27th, 2007
 

get() function fetches a character inlcuding the tab,blank space & newline  character.
 ex-
char c;
cin.get(c);

now if i write say Mysterious Girl.... it will first fetch M and assign it to c.
Then i have to put it in a loop to obtain the rest of the characters .


getline() function reads a whole line of text that ends with a newline character or RETURN key.

char c[20];
cin.getline(c,20);

now if i write mysterious gal...

it will get saved in array c.

smiles :)
mysterious gal

get() extracts char by char from a stream and returns its value (casted to an integer) whereas getline() is used to get a line from a file line by line. Normally getline is used to filter out delimiters in applications where you have a flat file(with thousands of line) and want to extract the output(line by line) using certain delimiter and then do some operation on it.

  Was this answer useful?  Yes

mysterysource

  • May 30th, 2015
 

if i am not wrong get() reads char by char and it does not read the blank spaces

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions