Hello everyone. I was writing somthing in C++ today and a little "issue" occured to me. How can you avoid the possibility of a buffer overrun when reading from STDIN into a character array? In this simple example
#include <iostream>
using namespace std;
int main ()
{
char *some_text = new char[10];
cout <<"Enter some sample text: ";
cin >> *some_text;
}
all seems well and good at first glance. But if someone enters more than 9 characters at the prompt they'll be a buffer overrun. The string of characters entered by the user is (I assume) copied into *some_text from a buffer outside the program. So how do you make sure no more than 10 characters are copied into *some_text? Begginers question I know, but an important one. Any answers appriciated.
Steven.