ok... quick and easy... cin.flush();
-
i asked a question refering to why my cin stopped working after the program had looped, my answer was cin.flush(); I applied that line to my code, and the program didnt reconize it,... if this is the way to reinitialize a cin for it works everytime the loop goes through, then why wont it work? is there a required header? painless see? thanks! ~SilverShalkin :rose:
-
i asked a question refering to why my cin stopped working after the program had looped, my answer was cin.flush(); I applied that line to my code, and the program didnt reconize it,... if this is the way to reinitialize a cin for it works everytime the loop goes through, then why wont it work? is there a required header? painless see? thanks! ~SilverShalkin :rose:
I'm sorry, it's cout that requires the .flush(); :-O The reason is that one needs to be cleared before you use the other. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
-
i asked a question refering to why my cin stopped working after the program had looped, my answer was cin.flush(); I applied that line to my code, and the program didnt reconize it,... if this is the way to reinitialize a cin for it works everytime the loop goes through, then why wont it work? is there a required header? painless see? thanks! ~SilverShalkin :rose:
Try with
cin.clear()
, which should resetcin
in case you had a formatting error. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
Try with
cin.clear()
, which should resetcin
in case you had a formatting error. Joaquín M López Muñoz Telefónica, Investigación y Desarrollook... that makes more sense... cin.clear(); but is that all? the line works but the program comes acrros the same thing... after you insert the GPA of the student "GPA is a float" the program prints the name and the gpa, then it asks for the name again, but when you press enter after the name, the program atomatically inserts the previouse GPA. thanks again.. "If i figuere it out, ill post :)" ~SilverShalkin :rose:
-
i asked a question refering to why my cin stopped working after the program had looped, my answer was cin.flush(); I applied that line to my code, and the program didnt reconize it,... if this is the way to reinitialize a cin for it works everytime the loop goes through, then why wont it work? is there a required header? painless see? thanks! ~SilverShalkin :rose:
That's because of the new line (character "\n") that you entered in previous cin, to fix this problem simply add statement "cin.ignore(1, '\n');" before the second use of cin. Example:
int x; float y; cin >> x; // first call, fine cin.ignore(1, '\n'); // this is a must cin >> y; // now there's no problem