Hello! I want to read a certain number of characters using cin stream of one. All I'll simply getline () works great for files but not when it is read from the keyboard. have therefore designed the following: Code: char s [50]; court <<"Input:"; cin.getline (s, 11, 'x'); court <<endl <<"read ["<<s <<"]"<<endl; which should lead to I 10 via keyboard sign reading, until I either a 11th enter, or 'x' press. but actually I ALWAYS (even if limitter = 'x') the input end with ENTER. is it ok according to standard, or is this simply the compiler / OS, that it does not work without a final ENTER ...?
I have the problem that I need a command that waits for an Enter and still reads more than up to the space. If I cin> variable>>; work, he reads it only to the blanks. If I cin.getline (variable, 50); While working, he reads everything but no one waits for my input and I in a loop applying it to make program more easily and then reads the one thing I spend next. Can someone help me there?
This is my loop Code: do ( menue (); court <<""; cin>> e; switch (e) ( case 1: schl.text_eingabe () <- This is called input break; case 2: schl.text_ausgabe (); break; case 3: (Schl.text_speichern); break; case 4: schl.verschl (); break; case 5: schl.entschl (); break; ) ) While (e! = 0); This happens in the input function: court <<"Please enter the text: \ n"; cin.getline (text, 49); Unfortunately, the command waits not now that what I type and the loop continues. With cin>> variable; goes just because it is not so read only up to the space
Code: void clearIn () ( cin.clear (); # If DAS_MIT_IGNORE_NICHT_FUNKTIONIERT cin.sync (); # Else cin.ignore (cin.rdbuf () -> in_avail ()); # Endif ) int main () ( ... cin>> e; (ClearIn) / / ignore characters in the input buffer. ... )