Data file handling | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Data file handling

i made this program but it goes to infinite loop whenever i try to input the second time (this program doesnt work on SL compiler so i am using cxxdroid). i am not able to figure out my mistake plz help me https://code.sololearn.com/cAWWSWiApu21/?ref=app

24th Sep 2018, 10:55 AM
Saurabh Tiwari
Saurabh Tiwari - avatar
3 Answers
+ 1
The last read operation in the first iteration of the loop is cin>>c. Now cin maintains an input buffer for all read operations and then copies data from this buffer. But this operation leaves a newline in the buffer, which is then interpreted by the cin.getline call, and the output is skipped. To remove the issue, add this after cin>>c: cin.ignore(numeric_limits<streamsize>(cin),'\n'); And include the header, <limits> What this does is remove all characters till a newline, and after removing the newline, it stops.
24th Sep 2018, 11:05 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 1
Saurabh Tiwari The numeric_limits part is just to specify the size of the cin's buffer. You can use a smaller number, or even 1 for this case.
24th Sep 2018, 11:28 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
- 1
Kinshuk Vasisht thnx for the help can you provide any alternative way of this as i am not familiar with limits
24th Sep 2018, 11:26 AM
Saurabh Tiwari
Saurabh Tiwari - avatar