Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   C & c++ (Some questions) (http://www.go4expert.com/forums/c-cpp-questions-t2463/)

jsload 7Jan2007 14:08

C & c++ (Some questions)
 
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

ever_thus 9Jan2007 01:25

Re: C & c++ (Some questions)
 
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.

DaWei 9Jan2007 04:37

Re: C & c++ (Some questions)
 
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).


All times are GMT +5.5. The time now is 05:16.