[Solved] c++ getline and ignore


When you write cin.ignore(0,'\n'), you’re saying “Ignore the characters in the stream until you have ignored 0 characters or you reach a ‘\n'”. Since you told the stream to ignore a maximum of 0 characters, it does nothing.

When you write cin.ignore(100, '\n'), you’re saying “Ignore the characters in the stream until you have ignored 100 characters or you reach a ‘\n'”. There probably isn’t going to be 100 characters, so you’re basically ignoring characters until the next newline. If you think about it, you’re ignoring the rest of the line.

0

solved c++ getline and ignore