Thread
:
Help with a small problem in C++
View Single Post
pichlo
2013-11-26 , 10:26
Posts: 6,453 | Thanked: 20,983 times | Joined on Sep 2012 @ UK
#
6
Incidentally, for line-based input like yours, the best practice is to always read a line at a time using standard functions like getline() that consume the terminating '\n', then parsing the string, as opposed to parsing the standard input directly. That way you not only avoid surprises of the "'\n' left over in the buffer" kind, but also get extra robustness for cases when the user replies with "3, you silly old program" to queries requesting only a number (hint: cin << number will only swallow the 3, the rest including the comma will be left in the input buffer for the next cin operation to read).
Quote & Reply
|
The Following 3 Users Say Thank You to pichlo For This Useful Post:
bandora
,
nokiabot
,
ranbaxy
pichlo
View Public Profile
Send a private message to pichlo
Find all posts by pichlo