Question on Pointers

#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;

void Paranoid(string *realmessage)
{
(*realmessage)[6] = '1';
realmessage->replace(9,1,"");
realmessage->insert(18, "ad");
realmessage->replace(15,2,"in");
realmessage->replace(23,7,"!");
realmessage->replace(4,3,"ali");
};

int main()
{
string message = "The friends are having dinner \n";
cout << message;

Paranoid(&message);
cout << message << endl;

return 0;
}

********************************************************************************

I don't understand the part of the array: (*realmessage)[6] = '1';
Can someone please explain it to me
realmessage is a pointer to string, so *realmessage is the string it points to. Now,when you have a string object and use [n] on it, nth char of that string is returned. The parentheses are there because * has lower priority than [] (I think..).
Topic archived. No new replies allowed.