What does c_str() do?

This is a discussion on What does c_str() do? within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by Eman oh no..foo and foo.data[0] is not the same thing.. hold on what're you saying (baffled), that ...

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,648
    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].
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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!

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21