I will talk about what happens in each of the four lines of code in your question, but first I have to say that your conclusion is not accurate. You are "tricked" by overloading the statement built into the string class. Although it is likely that internally, the string class supports an array of C-style characters, it is encapsulated and string is and should be treated as an opaque object other than a C-style string .
Now for each of your lines:
string *pointer = new string[runtimeAmmount];
In this line, pointer set to point to the newly allocated array of (empty) string objects. runtimeAmmount - the number of lines in the array, not the number of characters in a C-style string
string aString = "this";
This line builds a new empty line using the constructor of the (implicit) conversion from the class string : string(const char *) . (Note that in the context of a non-construct, for example aString = "this"; operator=(const char *) overload of the string class will be used.)
char bString[] = "that";
This is a typical C string, treated as an array of characters.
bString[3] = aString[3];
This uses the overloaded operator[] of the string class to return the character (reference), and then assigns it to the third character spot in the C-style character array.
Hope this helps.
source share