[C++] How to ignore inputs after n number of required inputs?
I have a code where it automatically fills in n number of observations for an integer vector using for loop. Here, the n is set to 4 so any number of inputs greater than 4 needs to be ignored – this is because instead of typing each input per line in console, I made it so that the user only needs to type a single line of n(s). For example, if the user wants to put 0,1,0,1 then he only needs to type 0 1 0 1 in the console.
The problem is that I want to implement additional codes that ignores user's input should he write number of observations that are greater than 4. Hence, 0 1 0 1 0. Currently, it seems that if I do this, the four numbers register as it should and it automatically skips to the part where the next cin is called.
How can I discard the fifth, or any inputs greater than n?
Submitted July 17, 2017 at 06:49AM by VonLuftwaffle
via reddit http://ift.tt/2uqD444