Use char pointer to point to the char array returned from string.data() : string data « string « C++ Tutorial






#include <iostream>
using std::cout;
using std::endl;

#include <string>
using std::string;

int main()
{
   string string1( "STRINGS" );

   const char *ptr1 = 0;
   ptr1 = string1.data();

   for ( int i = 0; i < string1.length(); i++ )
      cout << *( ptr1 + i ); // use pointer arithmetic

   return 0;
}
STRINGS"








15.10.string data
15.10.1.Use char pointer to point to the char array returned from string.data()