Simple quick qestion about streamsize

I use this line to ignore all but one letter given to a variable through 'cin' (thanks to vlad for suggesting it):
cin.ignore( numeric_limits <streamsize>::max(), '\n' );

But why the '\n' at the end? Everything else make sense, but not the '\n'. It irritates me... I like knowing why I type the things I do.
I don't know the context why did you need exactly these parameters, but:
cin.ignore( numeric_limits <streamsize>::max(), '\n' ); means skip everything until a newline character is met ('\n'). If you want to ignore everything that is left in the buffer then call cin.ignore( numeric_limits <streamsize>::max() );
Last edited on
closed account (o3hC5Di1)
Hi there,

The function takes two arguments, the first is the amount of characters to ignore, the second is a delimiting character.
The stream will stop ignoring whichever one of these two is first met, meaning it will stop either after the specified amount of characters, or when it encounters a linebreak - whichever comes first.

Hope that helps.

All the best,
NwN
I forgot to remove the ' , ' when I tried it without the '\n'. That's why it didn't compile.

Now I've tested the program without the newline stuff, and it acted very strange. But now I at least know why it's there =)

Thanks!
Topic archived. No new replies allowed.