Ch3_ClearFunction - //Line 5 cin.clear(); //Restore input...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//Input failure and the clear function #include <iostream> # using namespace std; u int main() { int a = 23; //Line 1 int b = 34; //Line 2 cout << "Line 3: Enter a number followed" << " by a character: "; //Line 3 cin >> a >> b; //Line 4 cout << endl << "Line 5: a = " << a << ", b = " << b << endl;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //Line 5 cin.clear(); //Restore input stream; Line 6 cin.ignore(200,'\n'); //Clear the buffer; Line 7 cout &lt;&lt; &quot;Line 8: Enter two numbers: &quot;; //Line 8 cin &gt;&gt; a &gt;&gt; b; //Line 9 cout &lt;&lt; endl &lt;&lt; &quot;Line 10: a = &quot; &lt;&lt; a &lt;&lt; &quot;, b = &quot; &lt;&lt; b &lt;&lt; endl; //Line 10 return 0; }...
View Full Document

Ask a homework question - tutors are online