data

Syntax:

    #include <string>
    const char *data() const;

The data method returns a pointer to the first character in the current string.

Note that no terminating null character is appended (see member c_str for such functionality).

For example:

#include <iostream>
#include <string>
using namespace std;
 
int main ()
{
    string str1="hello";
    const char *ch;
    size_t n=str1.length();
    ch=str1.data();
    for(int i=0;i<n;i++)
    {
        cout<<*(ch++);
    }
    cout<<'\0';
    return 0;
}

Related Topics: String operators, c_str