Let’s say I have an array:
string w[10];
and I have a statement:
if(w.size() > 10)
{
// How would I print out the 11th character?
char a = w[11];
cout << a << endl;
}
How would I print out the 11th character? I tried storing into a character a but it didn’t seem to print anything.
Why do you want to print outside of the bounds of an array? Printing any character past the size of your array is undefined and might cause a crash.
Also w[11] is actually the 12th element. Since the array is 0 based the 11th element is w[10].
Do you actually want the array do be dynamically sized? Because if you are trying to use a string perhaps you want an stl string? That is defined in the header
<string>and used via