What does cin.clear() do? Does it just destroy all user input or...what? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What does cin.clear() do? Does it just destroy all user input or...what?

3rd Dec 2018, 4:02 AM
Cheese Burger Joe
Cheese Burger Joe - avatar
2 Answers
+ 2
I guess you could get a better undestanding of the function if you go to a IDE like VSCode and get the function definition to see exactly what it does, that being said, you can check the link below and see a brief explanation on stackoverflow. https://stackoverflow.com/questions/1525535/delete-all-items-from-a-c-stdvector
3rd Dec 2018, 4:25 AM
Zenobio
Zenobio - avatar
+ 2
clear(), with no argument provided, simply resets the state of the flags failbit, eofbit and badbit, by assigning them the value of goodbit. These are used to check for errors encountered during operations. Here is a detailed reference: www.cplusplus.com/reference/ios/basic_ios/clear en.cppreference.com/w/cpp/header/io/basic_ios/clear
3rd Dec 2018, 8:06 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar