Hi guys. I'm still new to c++ so I kinda need some help here. I was wondering, when storing a series of words into an array, is there is any difference between using:
string Stuff[]={"random1", "random2",...};
and
char* Stuff[]={"random1", "random2",...};
Both seem to work equally well and give the same results. However, I am more concerned with the second one. Is there a deeper meaning to it other then just an array? They seem like an array of pointers to me, but I don't see how I can use them as pointers.
I hope I managed to phrase my question in an understandable way. Thanks for any help that I can get! :)
char* Stuff[] is an array of C-style string literals.
String literals end with a terminating null character '\0', so the first element "random1" will have 8 characters.
In C++, string literals are const, and because they are const, they are sometimes placed (if string pooling is enabled) in read-only memory.
std::string objects are a lot easier to use, and if you ever need a C-string for any reason, just use the std::string().c_str() method.
Basically, it's recommended that you use std::string.
*EDIT* about your pointer related questions, technically, it is an array of char pointers. They're pointers which point to the first element of their respective C-style string literals.