Using a Function to Modify a String Passed into It by Using Pointers - C++ Function

C++ examples for Function:Function Parameter

Description

Using a Function to Modify a String Passed into It by Using Pointers

Demo Code

#include <iostream> 
#include <string>
using namespace std; 

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

int main() //from  w ww  . ja v a2s.c o  m
{ 
  string message = "this is a test test test test"; 
  cout << message << endl; 

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

  return 0; 
}

Result


Related Tutorials