data

Syntax:

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

The function data() returns a pointer to the first character in the current string.

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++);
    }
    return 0;
}

Related Topics: String operators, c_str