In this exercise I am using Visual Studio 2017 and the std_lib_facilities header provided by Stroustrup.
Chapter 17 // Exercise 10Look at your solution of exercise 7. Is there any way that input could get the array to overflow; that is, is there any way you could enter more characters than you allocated space for (a serious error)? Does anything reasonable happen if you try to enter more characters than you allocated?
Fortunately, the version of cin.get() that I used only gets up to the specified amount of characters. So I pass it the char pointer then specify 256 (as that is the size of the array) and give it a deliminating character. So it will either stop reading at '!' or once it reads in 256 characters.
No comments:
Post a Comment