cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Question on Pointers
Question on Pointers
Oct 4, 2011 at 4:38pm UTC
maddogk9
(3)
#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
Oct 4, 2011 at 5:16pm UTC
hamsterman
(4538)
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.