I've had some issues with input in the past, and I was given this line, which helped to get rid of some residual newline, but after the first time it goes through the while loop, it prompts the user for input himself instead of taking it from the newline. I was wondering if anyone could tell me what this line means, and possibly if they could help me with my problem
It's like cin.ignore(10000,'\n');
It says that we go through 10000 character to first occurrence of '\n' . When it's found, simply ignore the '\n' and stop the ignore function. It simply means : Eat whatever before the target and eat the target too...So when you say cin.getline() it will read the new line.
because the getline() will stop when encounter the '\n' and if you don't use ignore,the '\n' is still in the input stream (first position) and when you use one more getline() it will input nothing.
numeric_limits
http://msdn.microsoft.com/en-us/library/yefe7a47(VS.80).aspx
Describes things about basic data types, like streamsize
So basically what it is saying is "ignore all the characters you get from cin until you find '\n' or you read as many characters as a stream can hold."
because the getline() will stop when encounter the '\n' and if you don't use ignore,the '\n' is still in the input stream (first position) and when you use one more getline() it will input nothing.
The 'A' will go into the input stream and is assigned to aChar;
But since you press enter key, the '\n' exist in the input stream now and will be the next character to be inputted.
When you call cin.getline(hehe,79) It encounters '\n' hence it stops and won't let you input anything else.
Oh i see. So, if that whole section of code were in a while loop, how would I go about making it to where the ignore line wouldnt ask for input after the first time it executes?
The reason for eliminating '\n' is for make the input stream ready for a getline. (maybe more I don't know)
And the reason for the ignore line is to clean up the input stream if you've done with all the inputs and want to clean it up so it will be ready for another inputs. "Clean what's left !".
But the getline already gets eliminates the '\n', so when the theoretical while loop restarts, theres nothing in the input stream, so the user has to input a '\n' himself to get past the ignore line, and i dont what that
The first time it goes through, there's a '\n' in the input stream that gets cleared, but the second time the while loop executes, there is no '\n' for the ignore line to ignore, so the user has to input one himself