I am new to programming, and I have some questions on get()
and getline()
functions in C++.
My understanding for the two functions:
The getline()
function reads a whole line, and using the newline character transmitted by the Enter key to mark the end of input. The get()
function is much like getline()
but rather than read and discard the newline character, get()
leaves that character in the input queue.
The book(C++ Primer Plus) that I am reading is suggesting using get()
over getline()
. My confusion is that isn't getline()
safer than get()
since it makes sure to end line with '
'
. On the other hand, get()
will just hangs the character in the input queue, thus potentially causing problem?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…