cplusplus.com
C++ : Forum : Beginners : cin.ignore()
 
cplusplus.com
Information
Documentation
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs


question cin.ignore()

zydeoN (29)
hello, why everybody puts cin.ignore() after a cin >>.
Some people say that cin can leave a terminating character in the stream. Well, i didnt understand that. What problems can it origin? give examples, please..
Warrior2089 (91)
You mean
cin>>cin.ignore();
?

Hell if I know, that makes no sense.
zydeoN (29)
No, i mean, for example you have an integer x. you do:
1
2
cin >> x;
cin.ignore();


Everybody use this, and i dont know why...
eker676 (427)
cin leaves the newline character in the stream. Adding cin.ignore() to the next line clears/ignores the newline from the stream.

This is used mainly with combinations of cin and getline. I can't think of any examples but over time you will find them if you use getline and cin together.

Take a look at this:
http://www.cplusplus.com/forum/articles/6046/
zydeoN (29)
thanks a lot, you helped me...
outsid3r (38)
ignore() will flush the input stream, just like C fflush(stdin), which is great for removing the annoying new lines stored at the end of the stream :P
Topic archived. No new replies allowed.