+ 2
Difference between getline and get
What is difference between just plain cin >>, cin.get(), and getline() in c++?
8 Answers
+ 2
Using cin.getline() reads a whole line, up to, but not including the Enter key.
Using cin.get() is the same, except it keeps the newline character.
Using just cin only takes characters to the first white space.
+ 2
I wasnât sure so did a quick search and found this.....
cin leaves the newline character in the stream. Adding cin.ignore() to the next line clears/ignores the newline from the stream.
http://www.cplusplus.com/forum/beginner/9148/
So if you just use cin and enter something without a space, the newline will be included in the input. The cin.ignore() will then remove the newline character.
+ 1
Iâm currently studying c++ as well so donât mind helping out. Iâve known perl for 18 years, got into php 10 years ago, and started being interested in c a few years ago. Decided recently to start studying it before I get too old to start.
0
Mike Thank you. My professor is very quick with his slides and if often bewildered by his presentation. If you donât mind, could you also explain the cin.ignore method and what types of arguments we could pass into cin.ignore(), cin.getline(), and cin.get()?
0
Oh I see. Thanks again, Mike! I really appreciate you putting your time into this.
0
Thatâs wonderful Mike. I am currently a freshmen in college taking the first computer science course and I am starting to like c++ even though it gets weird at times. And that is when I go to online communities like this to get help and fill in the gaps.
0
What is the difference between gets and getline in C++? 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. that is gets does the work letter to letter and whereas in the case of getline does it in line by line format
0
thanks deepak sharma but thatâs not the only difference though, right?