When i'm doing my code i got a problem.
When I use cin.getline(var,size,'\n');
it skips the line and goes to another line.
char name[50];
int number;
cin.getline(name,50,'\n');
cin>>number;
it skips the name line and goes to number. Why this is happen?
cin.getline not working
Page 1 of 11 Replies - 165 Views - Last Post: 19 November 2012 - 06:54 AM
Replies To: cin.getline not working
#2
Re: cin.getline not working
Posted 19 November 2012 - 06:54 AM
Do you have input prior to this? Chances are there is a new line in the input buffer.
Try adding
#include <limits>
and use std::cin.ignore(std::numeric_limits<streamsize>::max(), '\n' ); before the code you posted to eat up all the input currently in the input buffer, up to and including any new line character.
Try adding
#include <limits>
and use std::cin.ignore(std::numeric_limits<streamsize>::max(), '\n' ); before the code you posted to eat up all the input currently in the input buffer, up to and including any new line character.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|