+ 1
I can't Input UserName
SOLVED. The program is always skip second input, and go to third input without user inputing userName. please help me fix this :) code : int : comNum, time; char userName[20]; cin >> comNum; cin.getline(userName,20); cin >> time;
8 odpowiedzi
+ 11
Oh yeah, forgotten to cin.ignore(). Glad you figured it out yourself. :D
+ 10
cin.getline does not seem to be recognised on Code Playground. Try:
int comNum, time;
string username;
cin >> comNum;
getline(cin, username);
cin >> time;
Remember to split different input into multiple lines, e.g.
1
ValentinHacker
20
+ 5
check out "cin.get()"
and shouldn't "cin.getline" should be "geline(cin, userName)" ?
+ 2
the problem now solved. i use cin.ignore()before cin.getline :)
+ 2
cin.get(0) do basically the same thing as cin.ignore(). but there is a slight different.
+ 2
thanks for answering my questions @Cain Eviatar , @Hatsy Rei
+ 1
@Hatsy Rei now i can't input time :(
+ 1
i try this code on CodeBlocks.