Use the pointer to access the individual parts of the string - C++ Data Type

C++ examples for Data Type:string

Description

Use the pointer to access the individual parts of the string

Demo Code

#include <iostream>

using namespace std;

int main()//from   w  w w  .j  ava 2 s. co  m
{
  string s;
  string *ptrToString;

  s = "this is a test from  book2s.c o m";
  ptrToString = &s;

  for (unsigned i = 0; i < s.length(); i++){
    cout << (*ptrToString)[i] << " ";
  }

  cout << endl;
  return 0;
}

Result


Related Tutorials