+ 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;

21st Sep 2017, 10:35 AM
Mustakim Arianto
Mustakim Arianto - avatar
8 Answers
+ 11
Oh yeah, forgotten to cin.ignore(). Glad you figured it out yourself. :D
21st Sep 2017, 11:39 AM
Hatsy Rei
Hatsy Rei - avatar
+ 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
21st Sep 2017, 10:46 AM
Hatsy Rei
Hatsy Rei - avatar
+ 5
check out "cin.get()" and shouldn't "cin.getline" should be "geline(cin, userName)" ?
21st Sep 2017, 10:46 AM
Cain Eviatar
Cain Eviatar - avatar
+ 2
the problem now solved. i use cin.ignore()before cin.getline :)
21st Sep 2017, 11:11 AM
Mustakim Arianto
Mustakim Arianto - avatar
+ 2
cin.get(0) do basically the same thing as cin.ignore(). but there is a slight different.
21st Sep 2017, 11:26 AM
Cain Eviatar
Cain Eviatar - avatar
+ 2
thanks for answering my questions @Cain Eviatar , @Hatsy Rei
21st Sep 2017, 11:28 AM
Mustakim Arianto
Mustakim Arianto - avatar
+ 1
@Hatsy Rei now i can't input time :(
21st Sep 2017, 11:01 AM
Mustakim Arianto
Mustakim Arianto - avatar
+ 1
i try this code on CodeBlocks.
21st Sep 2017, 11:05 AM
Mustakim Arianto
Mustakim Arianto - avatar