I want to enter say "1" without having to press enter after typing "1". I don't mean x=getchar(); because after typing "1" the flow stops. Is there a way to also implicitly get carriage return stuck to the x?
I want to enter say "1" without having to press enter after typing "1". I don't mean x=getchar(); because after typing "1" the flow stops. Is there a way to also implicitly get carriage return stuck to the x?
It's possible, but there's no standard way of doing this.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I want to continue with "writeBill" after pressing "1", however the "1" in the buffer stops this from happening. How can I do this?
Code:if (kbhit) { switch(getche()) { case '1': writeBill(); break; case '2': retrieve(); break; // . . . . } }
Code:while ( 1 ) { if (kbhit) { what = getche(); } switch(what) { case '1': writeBill(); break; case '2': retrieve(); break; // . . . . } // maybe sleep() }
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.