does std::string store data differently than a char* on either stack or heap or is it just derived from char* into a class?
char is a primitive data type whereas String is a class in java. char represents a single character whereas String can have zero or more characters.
Think of (char *) as string. begin(). The essential difference is that (char *) is an iterator and std::string is a container.
string is an object meant to hold textual data (a string), and char* is a pointer to a block of memory that is meant to hold textual data (a string). A string "knows" its length, but a char* is just a pointer (to an array of characters) -- it has no length information.
char *A is a character pointer. it's another way of initializing an array of characters, which is what a string is. char A, on the other hand, is a single char. it can't be more than one char.
char*malloc or calloc or new or new[].
free or delete or delete[] when you're done.char[ N ] (constant N) array or string literal.
char* argument points to stack, heap, or global space.<algorithm> and such.std::stringnew or delete.
char*.new[] much as you would to obtain a char*.char* or literal.c_str() which returns a char* for temporary use.std::string::iterator type with begin() and end().
string::iterator is flexible: an implementation may make it a range-checked super-safe debugging helper or simply a super-efficient char* at the flip of a switch.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With