Thread: What does c_str() do?

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Eman
    oh no..foo and foo.data[0] is not the same thing..
    hold on what're you saying (baffled), that the characters are like member variables of the string object?
    With the implementation that I have in mind, the characters belong to a dynamically allocated array. There is a pointer member in the String object that points to the first character of this dynamically allocated array.

    When you access s[0], it accesses s.data[0], returning it by reference. Therefore, the address of s[0] is the address of s.data[0]. Hence, if &s is equal to &s[0], then &s is equal to &s.data[0].
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Quote Originally Posted by tabstop View Post
    So if I have a class that looks exactly the same..................
    oh crap.i see what you mean..thanks

    the "[]" is like overloaded operators which behaves like a function..
    ah yeah, I get you.
    Thanks for clarifying that!
    You ended that sentence with a preposition...Bastard!

Popular pages Recent additions subscribe to a feed