0

How to input two strings simultaneously one after other?

Please help me in my following code to Enter string number string in the same order but only first two (string and number) input get store and third string didn't get stored the other variable Please helo me in flushing the buffer because I forgot how to flush the buffer??? https://code.sololearn.com/cgN1xjh1E2Ai/?ref=app

1st Apr 2020, 12:53 PM
Abhay
Abhay - avatar
2 Respuestas
+ 2
Use `cin.ignore()` method to ignore newline entered after `cin>>na;` ``` cin.getline(name,20); cin>>na; cin.ignore(1,'\n'); cin.getline(other,100); ``` https://stackoverflow.com/questions/25475384/when-and-why-do-i-need-to-use-cin-ignore-in-c
1st Apr 2020, 1:01 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
0
Input like: String1 5 String2 cin>>na; reads until a space. getline method reads entire line. in your code: cin.getline(name,20); cin>>na; //after reading into na, everything next input read by the next getline method until next line... So if you press enter, it goes to 'other' array.. To store next line input to store in other and to consume enter, use getchar() method.. cin.getline(other,100); Abhay cin.getline(name,20); cin>>na; getchar(); cin.getline(other,100);
1st Apr 2020, 1:03 PM
Jayakrishna 🇮🇳