Using a const Reference to Get Speed and Unchangeable Data - C++ Function

C++ examples for Function:Function Parameter

Description

Using a const Reference to Get Speed and Unchangeable Data

Demo Code

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

string myFunction(const string *realmessage)
{
  string NewString = *realmessage;//from   w w  w . j  av a  2 s .c  om
  NewString[6] = 'i';
  NewString.replace(9, 1, "");
  NewString.insert(18, "ad");
  NewString.replace(15, 2, "in");
  NewString.replace(23, 7, "!");
  NewString.replace(4, 3, "ali");

  return NewString;
}

int main()
{
  string message = "this is a test from book2s.com";
  cout << message << endl;

  string NewMessage = myFunction(&message);
  cout << NewMessage << endl;

  return 0;
}

Result


Related Tutorials