C++ examples for Operator:delete
Allocating a pointer, using it, and then freeing it.
#include <iostream> #include <string> using namespace std; int main()/*ww w . ja v a 2s . c om*/ { string *phrase = new string("this is a test!"); cout << *phrase << endl; (*phrase)[20] = 'r'; phrase->replace(22, 4, "new"); cout << *phrase << endl; delete phrase; return 0; }