Trying to check size of some cin statement -
i have simple user input function reads user types, ignoring enter's , taking first character comes across. using cin.ignore statement because part of menu, , want replay menu if enter none of given options, once. want have if-statement true iff user entered 1 character (he may enter multiple enter's before character), wanted use sizeof or length, couldn't quite work. can this? appreciated. also, if should changed phrasing of question, please let me know. in advance.
char interface::leesin ( ) { char invoer; { invoer = cin.get(); } while (invoer == '\n'); cin.ignore(max,'\n'); return invoer; }
the following code snippet whereby user presented console menu , needs input character. cin read in 1 char , program can processing char. loop terminate, when user inputs char '9'.
#include <iostream> using namespace std; int main() { char ch; { //print menu here cin >> ch; // take in 1 char //perform action based on ch } while (ch != '9'); return 0; }
Comments
Post a Comment