Quote:Original post by Tradone
by the way, what's the difference between char* and string?
and which is better?
char * is a char array, or c-string, of unspecified location. It could dissappear from under you if it is a local array, like this:
char str[100];
Or if it is mallocated, or newed, then if someone deletes it you will have problems.
At worst, it could be a pointer to an individual character, accidentally being used as a string.
There are many other problems, such as ensuring that the string is ended in the nul character ('\0'), so that c-string functions know its size. Also, there is no way to find out how much free sapce is at the end of the string for appending things to it.
std::string is an object that is responsible for managing an array of characters. Under the hood, it works with char arrays. But it presents an easy to understand interface to us, we really don't care what it does underneath, but from above things like copying, passing to functions, testing equality and returning them work as expected.