C & c++ (Some questions)

Discussion in 'C++' started by jsload, Jan 7, 2007.

  1. jsload

    jsload New Member

    Joined:
    Jan 7, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. ever_thus

    ever_thus New Member

    Joined:
    Jan 3, 2007
    Messages:
    53
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  3. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    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).
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice