When and why do I need to use cin.ignore() in C++?

ignore does exactly what the name implies. It doesn’t “throw away” something you don’t need. Instead, it ignores the number of characters you specify when you call it, up to the char you specify as a delimiter. It works with both input and output buffers. Essentially, for std::cin statements you use ignore before you do … Read more

Why is reading lines from stdin much slower in C++ than Python?

tl;dr: Because of different default settings in C++ requiring more system calls. By default, cin is synchronized with stdio, which causes it to avoid any input buffering. If you add this to the top of your main, you should see much better performance: std::ios_base::sync_with_stdio(false); Normally, when an input stream is buffered, instead of reading one … Read more