I've been coding in c++ for a while now, and I use string variables quite a lot. One day, I stumbled upon a char* which can also be used to "store" a string of characters, and it's been bothering me ever since that I don't really know what a string is (and by "string", I don't mean a line of characters, I mean the <cstring> string). Is it a class? A struct? A typedef? I would really like someone to give me an intermediate explanation of the inner workings of string variables.
String is a class object. It contains it's own member variables and functions. Some common (and very handy) string class include (but not limited to) size(), length(), empty(), clear(), compare() and c_str(). String class objects also have overloaded operators, such as , (), += and = .
Cstrings, or 'character arrays' are basically remnants of the ol' days of C. They are not nearly used as often as string class objects; however, string class objects are still backwards compatible with cstrings via use of the c_str() member.
The <cstring> library also has a whole bunch of functions that can help you use character arrays more efficiently, but they will never be as robust as a <string> object.
Sometimes you are forced to use cstrings, when you'd really want to use strings. For example, if your program handles command-line arguments, you'd have to perform cstring operations... so it pays off to be equally good at using both cstrings and strings.
Here is a list of <string> class members. Here is a list of <cstring> functions.