Looking for data() function

Hi all,

In one of the articles someone used a function data() as follows:

string work = data();

without any further reference or definition. I have an excellent book on C++ (Stanley Lippman), but data() is not mentioned as a standard function.

I searched with google but couldn't find any information, I may have used the wrong search terms.

So I went looking with kdevelop and found the definition inside string.h:

1
2
3
4
5
6
7
8
9
      /**
       *  @brief  Return const pointer to contents.
       *
       *  This is a handle to internal data.  Do not modify or dire things may
       *  happen.
      */
      const _CharT*
      data() const _GLIBCXX_NOEXCEPT
      { return _M_data(); }


What I want to know is: is this definition part of the C++ standard?
Or is it glibc dependant (like the macro entry suggests)?
Where can I find docs on this function? What does it do exactly?

Anyone know more about this function?

Guus.
Yes, it is a standard function. For example in the case of std::string, it returns the internal char array: http://cplusplus.com/reference/string/string/data/

I think each std::container class has it, it returns the internal array with the stored elements.
Last edited on
Thanks, that was it.
closed account (3qX21hU5)
There is a member function for most containers called data, but in this example string work = data(); I don't think that is what they are using. Just looking at that example alone it looks like they have made their own function called data that returns a string.
Topic archived. No new replies allowed.