Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Array of objects using new operator in C++

#include<iostream>
#include<string>
using namespace std;
class forgetcode
{
    public:
    string name;
   forgetcode()
   {
       cout<<"\nConstructor";
   }
    void display()
    {
        cout<<name;
    }
    void getstring(string st)
    {
        name=st;
    }
    
};
   int main()
{
    forgetcode *f;
    try
    {
        f=new forgetcode[3];
    }
    catch (bad_alloc xa) { 
    cout << "Allocation Failure\n"; 
    return 1; 
  } 
    f[0].getstring("c");
    f[1].getstring("c++");
    f[2].getstring("java");
    for(int i=0;i<3;i++)
    {
        cout<<"\nString"<<i<<":";
        f[i].display();
    }
    return 0;
}