Titbits on security and string manipulation in c++

Even though majority of the applications use vectors to get user input and manipulate data there are some who also user character input stream or arrays to get these kind of data. I think we shouldnt be using such kind since over herewhen we use arrays there are chances of buffer overflows.Incase we have character array c[10] and we take the user input as cin >> c.

There is well ahead chance of buffer overflow, since the user can enter any number of values.
We can avoid this one way by limiting the cin.width. But this also doesnt restrict the user input completely or the other option would be we could use string by including string header.
This way we have the size always equal or less than the user input and no memory corruption or overflow.


Leave a Reply

Your email address will not be published. Required fields are marked *