Why doesn't it throw an exception or error?
Buffer overflows are an example of undefined behavior. The behavior is literally undefined: if you overflow the buffer, there is no guarantee what your program will do. This does not create an exception, because it will require many relatively expensive checks even in the correct code, and in C ++ the general philosophy is that you do not pay for what you do not need.
If you avoid raw arrays and raw (unthinkable) pointers and use the containers, strings, and algorithms of the C ++ standard library, you can easily avoid most situations that can lead to buffer overflows.
Do you get getline input instead?
You can use std::getline , which allows you to extract the "string" of characters in std::string , or you can use >> and extract directly to the std::string object, depending on what exactly you want to extract.
source share