Hello there, iam new to C langauge also to the C++ language. iam a Pyschologist , just turn to programming want to know how programming is done, read useful articles on internet sites( so a bit familiar now). Arise me two questions i)Why does C++ have a string class when there is already char * (a pointer to type character)? ii)How does C++'s string differ from C' string class? Thankyou to the Experts, Please reply me soon
Once you know the answer to the second question the answer to the first is obvious. C strings (they're not classes) are simply arrays of single characters. They're open to the air. You are responsible for making sure you're in the right part of them, and you can mess them up them easily. C++ strings are, as you say, a class. Classes are programming constructs that present an interface to the user, while keeping the actual data untouchable (except by the interface). Hope this helps.
Some of the beauties of C++ strings: as a class, they overload certain operators so that you can establish a value, compare, and append, with the '=', '==', and '+' operators. You don't have to worry about the size; it adapts. Methods are available for substring and character location and other useful manipulations. String stream operations are available for them, as well as for C strings. C strings can easily be assigned to C++ strings, and the C string member of a C++ string can be accessed (though not written to directly).