I've createed a buffer system, however determining a string read from a buffer is rather difficult compared to C#. Let's consider the following code that creates a char* to an array:
int Size = 6;
char* String = new char[ Size ]();
That'll create the pointer to a brand new array of a specified size. However, if I try to access an index outside of that size, an out of bounds error isn't shown:
String[ Size + 1 ];
Instead, for example I could "print" the array as if it were a string:
String[ 0 ] = 'S';
String[ 1 ] = 'T';
String[ 2 ] = 'R';
String[ 3 ] = 'I';
String[ 4 ] = 'N';
String[ 5 ] = 'G';
cout << String << endl;
However, this will not only print the characters within the original array but also random characters not within the original array, e.g. characters in indexes beyond the bounds of the array: (Example)
STRING&^%(^$$#%$*
Instead Of:
STRING
Why is this behavior happening and how can I avoid it?