i wanted clear doubt regarding function
cin.ignore(1,'\n');
code:
char x[80]; cin>>x; cin.ignore(1,'\n');
if user input word: paul smith
program looks first space in word , ignores/delete rest of characters?
hence program takes paul , discards smith?
right?
i'm getting confused! please explain in simple words because cannot understand explanation on google regarding issue.
cin.ignore(1,'\n');
is not useful. ignore 1 character.
cin.ignore(100,'\n');
will ignore 100 characters stop after encounters '\n'
.
in case,
cin>>x;
will read paul
x
. line
cin.ignore(1,'\n');
will consume space after paul
. hence, smith
left on input stream.
hence program takes paul , discards smith?
no. hope clear above.
Comments
Post a Comment